How to Get the Underlying DataRow of a DataGridViewRow

23-07-2012

How to get the underlying data row of the bound data table linked to a DataGridViewRow in a DataGridView?

How to get the underlying DataRow of a DataGridView.Row?

How to get the underlying DataRow matching to a Selected Row of a DataGridView?

How to map the DataGridView row to the datasource?

How to get back to the matching DataRow of the DataSource of a DataGridView Row?

Answer:

Use the DataBoundItem property of the DataGridViewRow in the following way.

// this code gets the matching data row of the data source bound to this data grid view (dataGridView1)
DataRow SelectedRow = ((DataRowView)(dataGridView1.SelectedRows[0].DataBoundItem)).Row;
// please scroll

Menol
ILT

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: