您的位置:首页 > 其它

vs2005 DataGridView添加行号

2009-05-30 14:00 411 查看
在DataGridView的RowPostPaint事件中添加:
private void dgvDetail_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
//using (SolidBrush b = new SolidBrush(dgvDetail.RowHeadersDefaultCellStyle.ForeColor))
//{
//    e.Graphics.DrawString((e.RowIndex + 1).ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + 4);
//}

Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
this.dgvDetail.RowHeadersWidth - 4,
e.RowBounds.Height);

TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
dgvDetail.RowHeadersDefaultCellStyle.Font,
rectangle,
dgvDetail.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: