Is it possible to show row number in the row header of a DataGridView?
I\'m trying with this code, but it doesn\'t work:
pri
This worked for me.
Private Sub GridView1_CellFormatting(sender As Object, e As DataGridViewCellFormattingEventArgs) Handles GridView1.CellFormatting
Dim idx As Integer = e.RowIndex
Dim row As DataGridViewRow = VDataGridView1.Rows(idx)
Dim newNo As Long = idx
If Not _RowNumberStartFromZero Then
newNo += 1
End If
Dim oldNo As Long = -1
If row.HeaderCell.Value IsNot Nothing Then
If IsNumeric(row.HeaderCell.Value) Then
oldNo = CLng(row.HeaderCell.Value)
End If
End If
If newNo <> oldNo Then 'only change if it's wrong or not set
row.HeaderCell.Value = newNo.ToString()
row.HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight
End If
End Sub