all groups > visual studio .net ide > august 2005 >
You're in the

visual studio .net ide

group:

DataSet sorting and user


DataSet sorting and user Jack
8/28/2005 12:00:00 AM
visual studio .net ide:
Hi again,

The datagrid will get a dataset. We can find out what record the user
double-clicks by the this.myDataGrid.CurrentCell.RowNumber property. But if
the user 'sorts' the datagrid, then this RowNumber property is no longer
valid - is that right? If so, how can this be tracked?

Thanks in advance...
Jack.


Re: DataSet sorting and user Scott M.
8/28/2005 10:54:04 AM
That's correct. The row index in the grid will not necessarily be the same
row index as in your DataSet. What you should do to find the DataSet index
that corresponds to the DataGrid index is:

Make sure that your DataSet stores primary key data for each row.
Make sure that this PK data is also used in your DataGrid (you don't have to
display it in the grid, but it should be stored in some hidden control at
the very least).
In your code, you can then "Find" the right row of the DataSet, based on the
PK of the row in the DataGrid like this:

(assume PartNumber is the PK field name and lblPartNum is a label in the
DataGrid that is bound to PartNumber)

Dim theRow As DataRow = ds.Tables(0).Select("PartNumber='" &
CType(e.Item.FindControl("lblPartNum"), Label).Text & "'")(0)

FindControl takes in only control names, not indexes and returns an array of
possible matching rows, so you have to specify which array element you want
at the end of the line: (0)

-Scott


[quoted text, click to view]

AddThis Social Bookmark Button