DataGridView控件中如何自动产生行号
程序代码:
Imports System.Text Imports System.Windows.Forms Imports System.Drawing Public Class Form1 Private Sub DataGridView1_RowPostPaint(sender As Object, e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint Dim mFont As New System.Drawing.Font("Cambria", 9, FontStyle.Italic) '设置字体字号 Dim rowIdx As Long = (e.RowIndex + 1).ToString() Dim centerFormat As New StringFormat() Dim Alignment = StringAlignment.Center Dim LineAlignment = StringAlignment.Center Dim headerBounds As New Rectangle(e.RowBounds.Left + 10, e.RowBounds.Top + 5, DataGridView1.RowHeadersWidth, e.RowBounds.Height) e.Graphics.DrawString(rowIdx, mFont, SystemBrushes.ControlText, headerBounds, centerFormat) End Sub End Class
[此贴子已经被作者于2017-11-16 08:03编辑过]