Results 1 to 2 of 2

Thread: DataGridView: How to show row #'s?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2009
    Posts
    258

    Question DataGridView: How to show row #'s?

    This is a simple one, but I haven't seen a way to do it. I have a DataGridView that is bound to a Sql-Server database, and it works fine. The only thing I'd like to add is the row # at the beginning of every row. Yes, I COULD set the first column as "RowNUm" and maintain it that way, but it seems that having the row # on each row should be a feature already provided to us.

    So, is there a way to have the DataGridView display a row number for each row?

  2. #2
    Hyperactive Member guyvdn's Avatar
    Join Date
    Oct 2002
    Location
    Belgium
    Posts
    336

    Re: DataGridView: How to show row #'s?

    I don't think there is a built in option for it but you can do it like this:

    VB.Net Code:
    1. Private Sub DataGridView1_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
    2.         e.Graphics.DrawString(e.RowIndex + 1, DataGridView1.Font, Brushes.Black, e.RowBounds.X + 15, e.RowBounds.Y + 5)
    3.     End Sub
    To deny our own impulses is to deny the very thing that makes us human

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width