Index of Currently Selected Row in DataGridView

ErikE picture ErikE · Aug 26, 2010 · Viewed 442.5k times · Source

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

Answer

fletcher picture fletcher · Aug 26, 2010

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.