views:

1388

answers:

3

I have a DataTable bound to a DataGridView. I have FullRowSelect enabled in the DGV. Is there a way to get the selected row as a DataRow so that I can get strongly typed access to the selected row's values?

+2  A: 

I'm not sure how to do it w/o a BindingSource, here is how to do it with one:

var drv = bindingSoure1.Current as DataRowView;
if (drv != null)
  var row = drv.Row as MyRowType;
Henk Holterman
A: 

You should be able to directly cast your selected row into the strongly typed row that was bound to the DataGridView.

Dillie-O
+2  A: 
DataRowView currentDataRowView = (DataRowView)dataGridView1.CurrentRow.DataBoundItem
DataRow row = currentDataRowView.Row
Stuart Dunkeld