Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access the Item bound to a DataGridView Row (WinForms)

How would I access the bound item for a specific row for a DataGridView bound to a Custom Collection?

like image 563
Dog Ears Avatar asked Jul 25 '09 13:07

Dog Ears


People also ask

What is DataGridView data binding?

The DataGridView control supports the standard Windows Forms data binding model, so it can bind to a variety of data sources. Usually, you bind to a BindingSource that manages the interaction with the data source.

What is difference between DataGridView and DataGrid control in Winforms?

The DataGrid control is limited to displaying data from an external data source. The DataGridView control, however, can display unbound data stored in the control, data from a bound data source, or bound and unbound data together.


1 Answers

MSDN: DataGridViewRow DataBoundItem Property

The DataBoundItem property of the DataGridViewRow seems to do the trick!

var product = (Product) _grid.SelectedRows[0].DataBoundItem;
like image 194
Dog Ears Avatar answered Sep 21 '22 01:09

Dog Ears