determining the index of a row in a datatable

  • Thread starter Thread starter JohnR
  • Start date Start date
J

JohnR

Sorry if this is has an obvious answer, but I can't find it...

I am using a datatable.select to obtain the rows in a datatable that meet
certain criteria. My question is this: for each of the datarows that are
returned to me as a result of the datatable.select how can I determine their
index in the datatable.rows collection?

For those interested in why, it is because the index in the datatable is the
same as the index of the same row in an infergistics ultragrid control, and
I need to access that row in the grid, and the grid itself does not have the
equivalent of the "datatable.select", so I would have to scan through all
the rows which would be too inefficient. So, I'm sort of cheating by using
the fact that the field I'm searching for is a primary key and I can use the
datatable.select method to quickly find it. Hopefully, I can then use the
index of the datatable as the index into the ultragrid to access my row.

Thanks, John
 
Hi Ken,

Thanks for your response, but I'm a little confused... it seems your
example shows how to find the datarow given the position in the
currencymanager. What I am looking for is how to find the index of a row
that is returned to me as a result of a DataTable.Select method.

Something like this:

FoundRows = DataSet.Tables("MyTable").Select("MyField = 'Hi There'")
'return row where primary key is "Hi There"
dim dr as datarow = FoundRows(0) 'get the first found row
dim RowIndex as integer = dr.GetRowIndex 'of course there is no such
method, but it is what I am looking for
'once I have the rowindex I can do this:
dr = DataSet.Tables("MyTable").rows(RowIndex) 'and this stmt will return
the same row as before

So my question is how can I find RowIndex for a DataRow given I have the
actual DataRow object?

Thanks, John
 
Back
Top