Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 568
  • 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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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