I'm using a databound Windows Forms DataGridView
. how do I go from a user selected row in the DataGridView
to the DataRow
of the DataTable
that is its source?
DataRow row = ((DataRowView)DataGridViewRow.DataBoundItem).Row
Assuming you've bound an ordinary DataTable
.
MyTypedDataRow row = (MyTypedDataRow)((DataRowView)DataGridViewRow.DataBoundItem).Row
Assuming you've bound a typed datatable.
See the article on MSDN for more information.