读书人

怎么给DataGrid的RowHeader添加序列号

发布时间: 2011-12-22 23:36:25 作者: rapoo

如何给DataGrid的RowHeader添加序列号?
在Microsoft Visual Studio 2005中,如何给DataGrid的RowHeader添加序列号?
例如第一行就是1,第二行2,第三行3...如此类推...


如何实现呢?

[解决办法]
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
using (SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, System.Globalization.CultureInfo.CurrentUICulture),
e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}

}

读书人网 >C#

热点推荐