Numeros en las filas de Un DataGridView
Poner numero de filas en el Datagridview automáticamente , a medida que incrementado la fila, este numero va incrementado así como muestra la imagen siguiente
Código fuente:
Private Sub DataGridView1_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
Try
'Captura el numero de filas del datagridview
Dim RowsNumber As String = (e.RowIndex + 1).ToString
While RowsNumber.Length < DataGridView1.RowCount.ToString.Length
RowsNumber = "0" & RowsNumber
End While
Dim size As SizeF = e.Graphics.MeasureString(RowsNumber, Me.Font)
If DataGridView1.RowHeadersWidth < CInt(size.Width + 20) Then
DataGridView1.RowHeadersWidth = CInt(size.Width + 20)
End If
Dim ob As Brush = SystemBrushes.ControlText
e.Graphics.DrawString(RowsNumber, Me.Font, ob, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
Catch ex As Exception
MessageBox.Show(ex.Message, "vb.net", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub