Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting row number in a DataGridView

How do you get row number DataGridView cell? Specifically, if a user has selected a single cell, how can you get that row number? It needs to access a particular cell based on what the user has selected.

I know that the RemoveAt method can be used to remove at the Focus, but you cannot get the row number at focus apparently?

Thanks for the help!

like image 357
Cyclone Avatar asked Sep 10 '09 01:09

Cyclone


2 Answers

You can simply use RowIndex on the current cell:

var row = dataGridView1.CurrentCell.RowIndex;
like image 60
Matt Hamilton Avatar answered Nov 07 '22 19:11

Matt Hamilton


this one works fine .

Private Sub DataGridView1_RowPrePaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPrePaintEventArgs) Handles DataGridView1.RowPrePaint

If e.RowIndex >= 0 Then
        Me.DataGridView1.Rows(e.RowIndex).Cells(0).Value = e.RowIndex + 1
    End If
End Sub
like image 32
Renjith.R Avatar answered Nov 07 '22 20:11

Renjith.R