Private Sub datagridview1_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles grid1.RowPostPaint
Dim strRowNumber As String = (e.RowIndex + 1).ToString
Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
If grid1.RowHeadersWidth < CInt((size.Width + 20)) Then
grid1.RowHeadersWidth = CInt((size.Width + 20))
End If
Dim b As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X + 15, _
e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) _
/ 2))
End Sub