C#中datagridview前添加序号

首先,双击datagridview事件中的RowPostPaint添加一个事件函数体,

然后,在函数体中添加如下代码:

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);

运行即可。。。。。

posted @ 2013-10-05 11:19  繁芙俗籽  阅读(571)  评论(0编辑  收藏  举报