jump to navigation

Sorting Datatables for Additional Processing June 13 2005

Earlier I mentioned a way of sorting data tables / data sets by using the DefaultView and the sort property. This works great if you are done with your data! If you need to process your data even further however, sorting by a view will only take place once the data is bound to the control. This means you won’t be able to manipulate the sorted data as expected.

Enter the “Select” property.

Datatables have a property called select which allows you to filter the rows in the datatable fairly quickly. Just re-direct the result of the Select into a DataRow array and you have datatable rows sorted.

e.g.

Dim dt as DataTable
Dim dr as DataRows()

dt = MakeSomeDataTableForMePlease()
dr = dt.Select(”", “column_name”)
Now ‘dr’ will be an array of the rows in ‘dt’ sorted by ‘column_name’

You can now go ahead and cycle through the sorted rows as normal

for i = 0 to dr.length - 1
‘ This will access a specific column name in the datarow :: dr(i).item(”column_name”)
next

Comments

Sorry comments are closed for this entry