How to count the number of selected rows in a DataGridView?
Let's say I highlighted 5 rows, how can I show it in message box?
Please help I'm using WinForms in C#!
you need to set YourGridView.MultiSelect=true
; MultiSelect
When the MultiSelect property is set to true, multiple elements (cells, rows, or columns) can be selected in the DataGridView control. To select multiple elements, the user can hold down the CTRL key while clicking the elements to select. Consecutive elements can be selected by clicking the first element to select and then, while holding down the SHIFT key, clicking the last element to select.
then you can use SelectRows.Count property SelectedRows
MessageBox.Show(yourDataGridView.SelectedRows.Count.ToString());
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