Link to home
Start Free TrialLog in
Avatar of mydasx
mydasx

asked on

datagridview row numbers

how do i number the rowheaders in datagridview?
Avatar of mydasx
mydasx

ASKER

The following code will override the rowpostpaint event and number the rows in the datagridview.  I am resizing the header statically here, you may want to be more dynamic with how you will size the header to deal w/ large row numbers.

Mydasx

PLEASE RETURN POINTS

Private Sub dataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
        Dim blackBrush As SolidBrush = New SolidBrush(DataGridView1.RowHeadersDefaultCellStyle.ForeColor)
        e.Graphics.DrawString(e.RowIndex.ToString(System.Globalization.CultureInfo.CurrentUICulture), DataGridView1.DefaultCellStyle.Font, redBrush, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4)
        blackBrush.Dispose()

        Dim totalRows As Integer = Me.masterSched.ToSchedule().RDPList.Count
        Dim numberWide As String = totalRows.ToString()
        Dim width As Integer = numberWide.Length
        Me.DataGridView1.RowHeadersWidth = e.RowBounds.Location.X + 10 + width * 10
    End Sub
ASKER CERTIFIED SOLUTION
Avatar of EE_AutoDeleter
EE_AutoDeleter

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial