Sort Dataset For Display

  • Thread starter Thread starter Phil Seaton
  • Start date Start date
P

Phil Seaton

This is a follow up to

"Everytime I add a new record in dataset, it will be added to the last
row.
It will become unsorted dataset even when I edit the primary key data.
Is
there anyhow I can sort a dataset without using dataview? I'm not
able to
find the particular row with this unsorted dataset using dataview. I
do not
want to loop the dataset just to find a record and this is not
efficient.
I'm using a treeview, so I need a tidy dataset. Any ideas?"

In terms of displaying the dataset (as a tree view) in a sorted
fashion I found this worked

Tree.Nodes.Clear()
Dim i, n As Integer
Dim parentrow As DataRow
Dim ParentTable As DataTable
ParentTable = mMPANDataSet.Tables(0)
For Each parentrow In ParentTable.Select("item is not null",
"item")
Dim parentnode As TreeNode
parentnode = New TreeNode(parentrow.Item("item"))
Tree.Nodes.Add(parentnode)
Next parentrow

the key here is that the sort (using dataset table select) is done in
the for each statement, the following does not work

Tree.Nodes.Clear()
Dim i, n As Integer
Dim parentrow As DataRow
Dim ParentTable As DataTable
ParentTable = mMPANDataSet.Tables(0)
For Each parentrow In ParentTable.Rows
Dim parentnode As TreeNode
parentnode = New TreeNode(parentrow.Item("item"))
Tree.Nodes.Add(parentnode)
Next parentrow
 
Back
Top