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

7 comentarios:

Anónimo dijo...

muy bueno man!!! te felicito anda de diez generalmente los codigos que se encuentran en internet son una cagada pero este anda de lujo abrazo!

killers dijo...

muy buen aporte pero me da error, ya que utilizo vb2010 y me marca el error..."DgvMostrarDatos" me indica que esta inaccesible, de donde lo hereda? o que biblioteca tengo que importar..desde ya muchas gracias

Unknown dijo...

cambiar "DgvMostrarDatos" por el nombre de tu grilla "MiDatagridView", yo tambien trabajo con vs2010 y no encuentro problema alguno.

KILLER dijo...

MUCHAS GRACIAS JHONY!!!...ANDA MUY BIEN EL CODIGO Y COMO DECIAS HABIA QE CAMBIAR EL NOMBRE POR EL DE MI DATAGRID...SALUDOS

Anónimo dijo...

EXPECTACULAR!!!, buenisimo, muchas gracias.

Anónimo dijo...

online sim dating game http://loveepicentre.com/faq/ arian dating
catholic dating help for women [url=http://loveepicentre.com]online dating meet timeframe[/url] dating with witch female
women dating younger men [url=http://loveepicentre.com/faq/]she's dating a younger girl[/url] transgender dating [url=http://loveepicentre.com/user/dhitzbps/]dhitzbps[/url] crystal lee dating

Anónimo dijo...

ILDER

excelente aporte!
Te dejo mi correo, podría pasarte otro par de trucos para que los publiques!

ilder98@hotmail.com