We help IT Professionals succeed at work.

how to access DataTable rows, as ordered by DefaultView?

ottenm
ottenm used Ask the Experts™
on
I am not able to influence the construction of a certain DataTable.  To display it's contents, I set an "order by" clause into table1.DefaultView.Sort.  Everything is good in the gui (asp.net DataGrid), but I am having trouble accessing the records programmatically in that same sorted order.

Is there a way to actually sort the records in the DataTable?

Thanks for any help-
VS 2003
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
.Net Senior Developer
Commented:
no the DefaultView is just a view!... to get the records ordered in the table you need to order in the source

Author

Commented:
Then how to access the data using the view (so they come out sorted)?

Author

Commented:

Found it, could also use for each:

        Dim v As DataView = table1.DefaultView
        While i < v.Count - 1
            Dim row As DataRowView = v.Item(i)
            Dim val As String = row("ColumnName")
            'etc.
        End While

Author

Commented:
What's the right thing to do if you answer your own question?