Find a Row Index in a DataSet Table

R

Rythm Music

I am trying to find what is the best method to locate a row in a DataSet
Table, using a Primary Key. I need to find the row and set focus on
that row. I know of two methods, one is using Dataview and the other is
using Table.Rows.Find.

The first method requires sort to be specified and this messes up the
order in which my data is displayed.
The second gives me a Row object but not the psoition where it is
located.

Any help will be great.
--Rythm
 
W

William Ryan eMVP

I'm assuming this is in the context of a datagird? Anyway, Normally I
prefer to use the DataView and set it's RowFilter so only the row I want
shows, then you can unset it, it can make things easier for the user and
doesn't require sorting.

However, assuming that you have the table in order and Row[20] or the
DataTable corresonpds to Row[20] of the grid.

for(int i =0, i < myDataSet.Tables[TableName].Rows.Count-1){
//Assume Colum 0 name PK is the Column with the value you want to find
which is say "20000"
if(dr((i)0) == "20000){myDataGrid.Select(i);}
}

This whole thing only works if the indexes match though and the user can't
sort the grid.... However, if this is ok the above approach should work for
you.

HTH,

Bill
 

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