在相应的datagridview里面添加RowPostPaint事件,代码如下:
private void AAADGV_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
//自动编号与数据库无关
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, AAADGV.RowHeadersWidth - 4,
e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), AAADGV.RowHeadersDefaultCellStyle.Font, rectangle,
AAADGV.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}