Penomoran Pada DatagridView VB.Net

0 comments
Cara menambahkan nomor pada DatagridView :


Tuliskan Kode program dibawah ini di event RowPostPaint di DataGridView

Private Sub RowPostPaint(sender As Object, e As DataGridViewRowPostPaintEventArgs)
Dim dg As DataGridView = DirectCast(sender, DataGridView) 
Dim rowNumber As String = (e.RowIndex + 1).ToString() 
While rowNumber.Length < dg.RowCount.ToString().Length
  rowNumber = "0" & rowNumber
End While
 
Dim size As SizeF = e.Graphics.MeasureString(rowNumber, Me.Font)
If dg.RowHeadersWidth < CInt(size.Width + 20) Then
  dg.RowHeadersWidth = CInt(size.Width + 20)
End If
 
Dim b As Brush = SystemBrushes.ControlText
 e.Graphics.DrawString(rowNumber, dg.Font, b, e.RowBounds.Location.X + 15, _
 e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
End Sub




Related Post :



0 comments:

Post a Comment

 
VB Source Code | © 2011 Design by DheTemplate.com and Theme 2 Blog

Find more free Blogger templates at DheTemplate.com - Daily Updates Free Blogger Templates