徐胜利

导航

为DataGridView添加行号

一,为DataGridView添加RowPostPaint事件

二,为该事件添加如下代码

private void dgvShow_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)

{

Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, this.dgvShow.RowHeadersWidth - 4, e.RowBounds.Height);                           TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), this.dgvShow.RowHeadersDefaultCellStyle.Font, rectangle,                                     this.dgvShow.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);

}

posted on 2012-09-12 19:19  xuvictory  阅读(208)  评论(0)    收藏  举报