I have a DatagridView control on a Windows form. It's selectionMode property is set to CellSelect.
I want to operate on DatagridViewRow based on selected cells. The DataGridView control is bound to a DataSource.
How to get the Row collection based on selected cells ?
You can get the selected cells, rows, or columns from a DataGridView control by using the corresponding properties: SelectedCells, SelectedRows, and SelectedColumns.
CheckBox column selection All the rows in a datagrid can be selected by interacting with an intuitive check box in the column header.
The answer provided as Linq does not work with the syntax provided. Datagridview does not support ienumerable so you have to use:
IEnumerable<DataGridViewRow> selectedRows = dgPOPLines.SelectedCells.Cast<DataGridViewCell>()
.Select(cell => cell.OwningRow)
.Distinct();
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