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?
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:
Private Sub DataGridView1_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
e.Graphics.DrawString(e.RowIndex + 1, DataGridView1.Font, Brushes.Black, e.RowBounds.X + 15, e.RowBounds.Y + 5)
End Sub