Sort Dataset For Display

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
 
R

Rajesh Patel

after insert a datarow, resort it. so, it won't remain unsorted.

Rajesh Patel
 

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