日期:2014-05-19  浏览次数:20812 次

如何给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);
}

}