find the DataRow associated with datagrid row

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
 
B

Bart Mermuys

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
 

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