jueves, 9 de junio de 2011

Agregar Numero de Fila en RowHeader del DatagridView


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