Damien Damien - 1 year ago 76
C# Question

How Do I Get the Selected DataRow in a DataGridView?

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?

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download