Hi there,
I have a small XML file that I want to read into a dataset. The XML file contains a sortorder node and I'd like to sort the data in the XML file using that node.
Funny thing is that the data in the DataSet does not get sorted correctly. Here's the XML file:
<?xml version="1.0" encoding="utf-8" ?>
<mylinks>
<mylink>
<url>Item 1</url>
<name>Name of Item 1</name>
<sortorder>10</sortorder>
</mylink>
<mylink>
<url>Item 2</url>
<name>Name of Item 2</name>
<sortorder>20</sortorder>
</mylink>
</mylinks>
and here's the
VB code I am using:
Code:
Dim MyDataSet As New DataSet
MyDataSet.ReadXml("links.xml")
Dim MyDataView As DataView = MyDataSet.Tables(0).DefaultView
MyDataView.Sort = "sortorder DESC"
For Each MyDataRow As DataRow In MyDataView.Table.Rows
MessageBox.Show("Item is " & MyDataRow(0))
Next
DataGrid1.DataSource = MyDataView
The weird thing is that the For Each loop does *not* return the items in the requested order. That is, Item 1 comes first, then Item 2.
However, the DataGrid *does* display the data in the correct order.
Is there anything I should do to retrieve the data from the DataSet in the right order using For Each or For? I know it's in there in the right order, because the DataGrid can display the data correctly....
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.