Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all selected rows if only parts of rows are selected?

How to select all rows in which something is seleccted? Say we have selected 10 items in all in difrent/same columns, in multiple rows like this:

enter image description here

And we want to get result similar to

var selected = ElementsTableView.SelectedRows.Cast<DataGridViewRow>();

yet for all rows in which is selected at least one column item. How to do such thing with WinForms in C#?

like image 570
myWallJSON Avatar asked Nov 24 '25 14:11

myWallJSON


1 Answers

Try this:

var selected = ElementsTableView
               .SelectedCells
               .Cast<DataGridViewCell>()
               .Select(c => c.OwningRow)
               .Distinct();
like image 133
Hamlet Hakobyan Avatar answered Nov 27 '25 04:11

Hamlet Hakobyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!