<好东西大家分享>
显示结果如下图:
http://s9/mw690/9c47a152gx6BIgvj7iU88&690
设置方法:
在DataGridView的RowPostPaint事件中进行绘制;
private void DataGridView1_RowPostPaint(object sender,
DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y, DataGridView1.RowHeadersWidth - 4,
e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
DataGridView1.RowHeadersDefaultCellStyle.Font, rectangle,
DataGridView1.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
运行程序即可显示行号;
加载中,请稍候......