Cảm ơn @ Gabriel-Perez và @Groo, ý tưởng tuyệt vời! Trong trường hợp những người khác muốn nó, đây là một phiên bản trong VB thử nghiệm trong Visual Studio 2012. Trong trường hợp của tôi, tôi muốn các con số xuất hiện trên bên phải liên kết trong Row Header.
Private Sub MyDGV_RowPostPaint(sender As Object, _
e As DataGridViewRowPostPaintEventArgs) Handles MyDataGridView.RowPostPaint
' Automatically maintains a Row Header Index Number
' like the Excel row number, independent of sort order
Dim grid As DataGridView = CType(sender, DataGridView)
Dim rowIdx As String = (e.RowIndex + 1).ToString()
Dim rowFont As New System.Drawing.Font("Tahoma", 8.0!, _
System.Drawing.FontStyle.Bold, _
System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Dim centerFormat = New StringFormat()
centerFormat.Alignment = StringAlignment.Far
centerFormat.LineAlignment = StringAlignment.Near
Dim headerBounds As Rectangle = New Rectangle(_
e.RowBounds.Left, e.RowBounds.Top, _
grid.RowHeadersWidth, e.RowBounds.Height)
e.Graphics.DrawString(rowIdx, rowFont, SystemBrushes.ControlText, _
headerBounds, centerFormat)
End Sub
Bạn cũng có thể nhận phông chữ mặc định, rowFont = grid.RowHeadersDefaultCellStyle.Font
nhưng có thể không tốt. Ảnh chụp màn hình bên dưới đang sử dụng phông chữ Tahoma.
![Example on windows 7](https://i.stack.imgur.com/v084W.png)
Không chắc chắn mọi người phải đối mặt với điều này: Tôi không thể đặt giá trị của HeaderCell trước Form_Load() - đó là trong CTOR của biểu mẫu. –