RowHeader display in VB.NET windows application

Unknown | 2:12 AM |

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





Category:

About http://dotnetvisual.blogspot.in/:
DOT NET TO ASP.NET is a web application framework marketed by Microsoft that programmers can use to build dynamic web sites, web applications and web services. It is part of Microsoft's .NET platform and is the successor to Microsoft's Active Server Pages (ASP) technology. ASP.NET is built on the Common Language Runtime, allowing programmers to write ASP.NET code using any Microsoft .NET language. create an application very easily ....