
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 + 10, e.RowBounds.Location.Y + 4);
}
本文介绍了一种在DataGridView控件中自定义显示RowIndex的方法,通过使用RowPostPaint事件,可以实现在每行前面显示行索引的功能。这种方法适用于Windows Forms应用程序中需要直观展示数据行编号的场景。
1816

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



