HOW TO LOOP THROUGH SORTED DATAVIEW?

  • Thread starter Thread starter Aric Levin
  • Start date Start date
A

Aric Levin

I have a Dataview that I read from a Dataset.
I am trying to sort the items in the Dataview and read the sorted items, but
it does not display the sorted items.

Here is the code:

DataView myDataView = oDS.Tables[0].DefaultView;
// By default, the first column sorted ascending.
myDataView.Sort = Sort;

for (int iSorted=0; iSorted<myDataView.Count; iSorted++)
{
DataRow tmpRow = myDataView.Table.Rows[iSorted];
System.Diagnostics.Debug.WriteLine(tmpRow[ColNo-1].ToString());
}

Thanks,

Aric Levin
Sounddogs.com
 
You have to loop through the DataView and not the DataTable. The DataView
has a collection of DataRowView objs. In VB it is something like this
dim oneViewRow as DataRowView
for each oneViewRow in myDataView
MsgBox(oneViewRow("FieldName").ToString())
MsgBox(oneViewRow(FieldIndex).ToString())
next

You are a C# programmer, but you will get the drift.
 
Back
Top