954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help: Numbering DataGrid RowHeader?

I have a DataGrid table like this: [img]http://ni8.upanh.com/b1.s24.d1/f869170161faa9e6ad2c272d6f66228e_40513398.capture.png[/img]
How could I change the plain-looking arrows in the RowHeader into row number (Like 1,2,3...)???
Thanks for any help from you guys!

Eternal Newbie
Newbie Poster
20 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

You can use SQL aliases on your sql query.
e.g :

select Name as '1', City as '2' from Address
Jx_Man
Nearly a Senior Poster
3,329 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
 

Thks, but my problem here is that I can't change DataGrid RowHeader to auto-generated numbers by VB.Net code, not by SQL. Any options?

Eternal Newbie
Newbie Poster
20 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 
Private Sub datagridview1_RowPostPaint(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles grid1.RowPostPaint
        Dim strRowNumber As String = (e.RowIndex + 1).ToString
        Dim size As SizeF = e.Graphics.MeasureString(strRowNumber, Me.Font)
        If grid1.RowHeadersWidth < CInt((size.Width + 20)) Then
            grid1.RowHeadersWidth = CInt((size.Width + 20))

        End If

        Dim b As Brush = SystemBrushes.ControlText
        e.Graphics.DrawString(strRowNumber, Me.Font, b, e.RowBounds.Location.X + 15, _
                              e.RowBounds.Location.Y + ((e.RowBounds.Height - size.Height) _
                                                       / 2))
    End Sub
princenathan
Newbie Poster
8 posts since Oct 2010
Reputation Points: 8
Solved Threads: 2
 

Thanks Ezz, I didn't ask for DataGridView but I finished it based on ur idea. Great help! :)

Eternal Newbie
Newbie Poster
20 posts since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: