HOW TO LOOP THROUGH SORTED DATAVIEW?

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
 
C

Chris Botha

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.
 

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