How Do I Get the Selected DataRow in a DataGridView?
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;
DataRowView currentDataRowView = (DataRowView)dgv1.CurrentRow.DataBoundItem
DataRow row = currentDataRowView.Row
You should be able to directly cast your selected row into the strongly typed row that was bound to the DataGridView.
It is possible by getting following property:
this.dataGridView.SelectedRows
One obtains a collection of type: DataGridViewSelectedRowCollection. It contains items of type: DataGridViewRow.
Then one can get bounditem with ones own type in following way:
DataGridViewSelectedRowCollection list = this.dataGridViewInventoryRecords.SelectedRows;
MyType selectedItem = (MyType)list[0].DataBoundItem; //[0] ---> first item