datagridview显示行号

简介: private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)        {            Rectangle rectangle = new Rectangle(e.

private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
                e.RowBounds.Location.Y,
                dataGridView1.RowHeadersWidth - 4,
                e.RowBounds.Height);


            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                dataGridView1.RowHeadersDefaultCellStyle.Font, rectangle,
                dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }

 

 

 

另一种也是在这个事件下面下面 用了个for循环来做index+1的单元格赋值,效率太慢了。
目录
相关文章
C#编程-72:dataGridView删除行
C#编程-72:dataGridView删除行
279 0
|
2月前
Datagridview 显示当前选中行
Datagridview 显示当前选中行
23 0
|
4月前
dataGrid 删除行和添加行
dataGrid 删除行和添加行
29 0
C#编程-20:DataGridView在HeaderCell中显示行号的方法
C#编程-20:DataGridView在HeaderCell中显示行号的方法
312 0
C#编程-20:DataGridView在HeaderCell中显示行号的方法
C#编程-79:DataGridView分页显示
C#编程-79:DataGridView分页显示
153 0
C#编程-79:DataGridView分页显示
|
C#
C# DataGridView 在最左侧显示行号方法
代码: private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { DataGridView dgv = send...
2420 0