below code shows how to do that.
Just you need to pass your datagridview in below function and it will generate auto number to Header cell.
NOTE: First you have to bind the datagridview with data then call the below function.
Public Sub AutoNumberRowsForGridView(ByVal dataGridView As DataGridView)
If dataGridView IsNot Nothing Then
Dim count As Integer = 0
While (count <= (dataGridView.Rows.Count - 2))
dataGridView.Rows(count).HeaderCell.Value = String.Format((count + 1).ToString(), "0")
count += 1
End While
End If
End Sub
Or Go through this link-
how-to-add-an-autonumber-column-in-a-datagridview/[
^]