Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Index of Currently Selected Row in DataGridView

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).

like image 530
ErikE Avatar asked Aug 26 '10 18:08

ErikE


People also ask

How to get the currently selected row in DataGridView c#?

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.

How do I get the selected cell index in DataGridView in VB net?

You can get the selected cell by using DataGridView. CurrentCell property. You can paste the value in the DataGridView cell by the following code.

What is e RowIndex in C#?

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.


1 Answers

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.

like image 114
fletcher Avatar answered Sep 28 '22 18:09

fletcher