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?
The datarow is an object in a datatable. A DataView (usable with the name DefaultView) is a seperated table in the DataTable where the sort and rowselections are properties from.
A DataRow represent a row of data in data table. You add data to the data table using DataRow object. A DataRowCollection object represents a collection of data rows of a data table.
The DataGridViewRow class is used to access the individual cell elements, as well as to adjust the appearance and behavior of the row user interface (UI), such as height and cell style. Typically, you will want all rows or most rows in the control to share the same characteristics.
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.
DataTable table = grdMyGrid.DataSource as DataTable; DataRow row = table.NewRow(); row = ((DataRowView)grdMyGrid.SelectedRows[0].DataBoundItem).Row;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With