• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 571
  • Last Modified:

datagridview row numbers

how do i number the rowheaders in datagridview?
0
mydasx
Asked:
mydasx
1 Solution
 
mydasxAuthor Commented:
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
0
 
EE_AutoDeleterCommented:
mydasx,
Because you have presented a solution to your own problem which may be helpful to future searches, this question is now PAQed and your points have been refunded.

EE_AutoDeleter
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now