find the DataRow associated with datagrid row

  • Thread starter Thread starter Ryan Liu
  • Start date Start date
R

Ryan Liu

Hi,

Is there better way to find the DataRow associate with row of a datagrid?

Now I put ID column(PK) as a column in a datagrid, and get this cell value
of the datagrid current row (DataGrid.CurrentRowIndex), then use
DataTable.Rows.Find(id) to find the datarow.

I feel this way is not generic. Is there better way to find the associated
DataRow?

System internally must know how they are associated, since I can edit the
datatable value in datagrid.

Thanks!
Ryan
 
Hi,

Ryan Liu said:
Hi,

Is there better way to find the DataRow associate with row of a datagrid?

Now I put ID column(PK) as a column in a datagrid, and get this cell value
of the datagrid current row (DataGrid.CurrentRowIndex), then use
DataTable.Rows.Find(id) to find the datarow.

I feel this way is not generic. Is there better way to find the associated
DataRow?

Maybe this is what you want:

DataRowView currentRowView =
(DataRowView)BindingContext[dataGrid1.DataSource,
dataGrid1.DataMember].Current;
DataRow currentRow = currentRowView.Row;

HTH,
Greetings
 
Back
Top