How do I get a DataRow from a row in a DataGridView
c#, datagridview, datatable, winforms
Solution
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.
Problem
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?