XML driving me nuts

M

MadCrazyNewbie

Hey Group,

A quick question:

Im Using the following code for a xml project:

Private Sub frmSystemUsers_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Users.ReadXml("..\dsSystemUsers.xsd")
dgdSystemUsers.DataSource = Users.Tables(0)
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnAdd.Click
txtUsersname.Enabled = True
txtPassword.Enabled = True
txtAccess.Enabled = True
Dim drSystemUsers As DataRow
drSystemUsers = Users.Tables(0).NewRow
Users.Tables(0).Rows.Add(drSystemUsers)
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdate.Click
Dim swSystemUsers As System.IO.StreamWriter = New
System.IO.StreamWriter("Users.xml")
swSystemUsers.Write(Users.GetXml.ToString)
swSystemUsers.Flush()
swSystemUsers.Close()
Users.Clear()
Users.ReadXml("users.xml")
dgdSystemUsers.DataSource = Users.Tables(0)
txtUsersname.Enabled = False
txtPassword.Enabled = False
txtAccess.Enabled = False
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnDelete.Click
Dim drSystemUsers As DataRow
drSystemUsers = Users.Tables(0).NewRow
Users.Tables(0).Rows.Remove(drSystemUsers)
End Sub

And here is my example XML file:

<users>
<user>
<name>Simon.Green</name>
<password>1</password>
<role>Manager</role>
</user>
<user>
<name>Keith.Taylor</name>
<password>2</password>
<role>Manager</role>
</user>
<user>
<name>Paul.codd</name>
<password>3</password>
<role>Manager</role>
</user>
<user>
<name>James.Peck</name>
<password>4</password>
<role>Manager</role>
</user>
</users>

I have a Datagrid on my form bound to SystemUsers.User. Why is it when I
load my form, I don`t see data in the Datagrid on my form, from Users.XML?

Many Thanks
MCN
 
O

One Handed Man \( OHM - Terry Burns \)

You need this at least at the beginning.

<?xml version="1.0" encoding="utf-8" ?>




--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
C

Cor Ligthert

Hi Simon,

Changed it completly,

There are no textboxes anymore and I do not say it is complete, one thing to
keep in mind that an error in this solution (as well in your own) by writing
the xml file will delete that completly.

However try it, I hope it helps?

Cor

\\\
Private Users As New DataSet
Private dvUsers As DataView
Private cma As CurrencyManager
Private Sub frmSystemUsers_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Users.ReadXml("dsSystemUsers.xml")
dvUsers = New DataView(Users.Tables(0))
dgdSystemUsers.DataSource = dvUsers
dvUsers.AllowNew = False
cma = DirectCast(BindingContext(dvUsers), CurrencyManager)
End Sub
Private Sub btnAdd_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnAdd.Click
Dim drSystemUsers As DataRow
drSystemUsers = Users.Tables(0).NewRow
Users.Tables(0).Rows.Add(drSystemUsers)
End Sub
Private Sub btnUpdate_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnUpdate.Click
cma.EndCurrentEdit()
Users.WriteXml("dsSystemUsers.xml")
Me.Close()
End Sub
Private Sub btnDelete_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnDelete.Click
dvUsers(cma.Position).Delete()
End Sub
///
 
M

MadCrazyNewbie

yer sorry forgot to include that bit in the paste, but it is in there:/

Cheers
MCN
 
O

One Handed Man \( OHM - Terry Burns \)

Try adding a row to a table manually and then doing a writeXML, compare the
format

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing
 
M

MadCrazyNewbie

Hi Cor,

Thanks for that, on this solotion what would be the best way to format my
datagrid? For example setting my Coloum Widths, or isn`t it possible?

Many Thanks
MCN
 
C

Cor Ligthert

Simon,

I was expecting this however I was waiting for that to make the sample more
clear. This at the end of the load event.

\\\
Dim ts As New DataGridTableStyle
ts.MappingName = dvusers.tables.tostring
Dim column As New DataGridTextBoxColumn
column.TextBox.MaxLength = 50
column.MappingName = "name"
column.HeaderText = "User Name"
column.Width = 250
column.NullText = String.Empty
ts.GridColumnStyles.Add(column)
column = DataGridTextBoxColumn
column.TextBox.MaxLength = 50
column.MappingName = "password"
column.HeaderText = "Password"
column.Width = 250
column.NullText = String.Empty
ts.GridColumnStyles.Add(column)
etc etc
dgdSystemUsers.TableStyles.Add(ts)
///

I hope this helps?

Cor

"> Thanks for that, on this solotion what would be the best way to format my
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top