Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataView Question

Status
Not open for further replies.

MikeDamone

Programmer
Oct 21, 2003
106
US
I have a datatable that I am adding rows to on the fly. Then I'm setting the datatable equal to a dataview for sort purposes. Then I want to loop through the sorted dataview and build an html table.

The problem I have is that the row indexes of the dataview table do not reorder when I sort, so the information I'm displaying is out of order. The row indexes remain what they were on the original datatable. Is there a way to loop through using row indexes in a sorted manner? Thanks
 
Wait a sec..

when you say

Then I'm setting the datatable equal to a dataview for sort purposes.

you mean that the dataview.table equals yourDatatable, right?

if:

Code:
yourDataview.sort = yourColumnAsstring

doesn't work, you can use an "ORDER BY columnName (ASC or DESC" in your select query.

Hope it's good enough to help you
 
oops,

sure you can't use "ORDER BY" 'cause you're addin' rows on the fly, sorry about that.
 
Just set the dataview:
'dt is your DataTable
Code:
Dim dv As New DataView(dt, "Field1 Is Not Null", "OrderField", DataViewRowState.Unchanged)

The dv, consists of all rows in dt whose Field1 is not Null and ordered by the the OrderField.

You can now loop through it:
Code:
For Each dr As DataRowView In dv
    'Codes here
Next

Regards,
mansii
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top