Click here to Skip to main content
15,896,207 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi
I have an xml file and try to load into datagridview, how can I save the xml after I sort it by desc?

VB
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)


VB
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 5:54am
v2

You should sort the table before save to xml file:

VB
Dim dv As New Dataview(DS.Tables(0))
dv.Sort="ID DESC"
DS.Tables(0)=dv.ToTable
 
Share this answer
 
v2
First of all you need to understand Scope of variables[^]
And here[^] you'll find complete example (ReadXml & WriteXml).
 
Share this answer
 
Comments
ProEnggSoft 9-Mar-12 11:44am    
Good links. My 5
Maciej Los 9-Mar-12 13:12pm    
Thank you ;)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900