Private Sub dgvSubscriptions_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles dgvSubscriptions.RowPostPaint
Try
' Dim b As SolidBrush = New SolidBrush(dgvSubscriptions.RowHeadersDefaultCellStyle.ForeColor)
'e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4)
Dim dg As DataGridView = DirectCast(sender, DataGridView)
' Current row record
Dim rowNumber As String = String.Empty
rowNumber = (e.RowIndex + 1).ToString()
' Format row based on number of records displayed by using leading zeros
While rowNumber.Length < dg.RowCount.ToString().Length
rowNumber = "0" & rowNumber
End While
' Position text
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
' Use default system text brush
Dim b As Brush = SystemBrushes.ControlText
' Draw row number
e.Graphics.DrawString(rowNumber, dg.Font, b, e.RowBounds.Location.X + 15, e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) / 2))
Catch ex As Exception
Utils.LogHandler.HandleError(ex)
End Try
End Sub
No comments:
Post a Comment