Click here to Skip to main content
14,384,739 members
Rate this:
Please Sign up or sign in to vote.
Hi
I have an xml file and try to load into datagridview, how can I save the xml after I sort it by desc?

DS.ReadXml(Application.StartupPath & "\user.xml")
       Dim DS As New DataSet
       If DS.Tables(0).Rows.Count = 0 Then
           MsgBox("nothing")
       Else
           Dim i As Integer = 0
           For Each r As DataRow In DS.Tables(0).Rows
               dtgUser.Rows.Insert(i, r("ID"), r("Name"))
               i = i + 1
           Next
       End If
       dtgUser.Sort(dtgUser.Columns("ID"), System.ComponentModel.ListSortDirection.Ascending)


Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
           
        DS.WriteXml(Application.StartupPath & "\user.xml")
            
    End Sub


[Edit - Removed check from Treat my content as plain text, not as HTML box so the code blocks will work]
Posted
Updated 23-Feb-12 6:54am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

First of all you need to understand Scope of variables[^]
And here[^] you'll find complete example (ReadXml & WriteXml).
   
Comments
ProEnggSoft 9-Mar-12 11:44am
   
Good links. My 5
Maciej Los 9-Mar-12 13:12pm
   
Thank you ;)
Rate this:
Please Sign up or sign in to vote.

Solution 2

You should sort the table before save to xml file:

Dim dv As New Dataview(DS.Tables(0))
dv.Sort="ID DESC"
DS.Tables(0)=dv.ToTable
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100