最简单的方法是在Datagridview的事件RowPostPaint事件下面添加如下代码即可
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{SolidBrush b = new SolidBrush(this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor);
e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), this.dataGridView1.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}
本文介绍了一种在DataGridView中自定义行号显示的方法。通过重写RowPostPaint事件,可以实现对每行前面的行号进行个性化设置,如添加文字、改变颜色等。
2045

被折叠的 条评论
为什么被折叠?



