It's that simple. How do I get the index of the currently selected Row
of a DataGridView
? I don't want the Row
object, I want the index (0 .. n).
To get the selected rows in a DataGridView controlUse the SelectedRows property. To enable users to select rows, you must set the SelectionMode property to FullRowSelect or RowHeaderSelect.
You can get the selected cell by using DataGridView. CurrentCell property. You can paste the value in the DataGridView cell by the following code.
As the object suggests (GridViewUpdateEventArgs) 'e' stands for the events relating to the update of a grid view. You can get similar method signatures that relate to other events such as deletions etc. The 'RowIndex' relates to the index of the row on which this event was fired.
There is the RowIndex
property for the CurrentCell
property for the DataGridView.
datagridview.CurrentCell.RowIndex
Handle the SelectionChanged
event and find the index of the selected row as above.
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