DataGridView中实现自动编号

DataGridView中实现自动编号

private void materialCheckGridView_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
    Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
        e.RowBounds.Location.Y,
        materialCheckGridView.RowHeadersWidth - 4,
        e.RowBounds.Height);
    TextRenderer.DrawText(e.Graphics,
            (e.RowIndex + 1).ToString(),
            materialCheckGridView.RowHeadersDefaultCellStyle.Font,
            rectangle,
            materialCheckGridView.RowHeadersDefaultCellStyle.ForeColor,
            TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}

 

posted on 2019-01-29 14:58  HubbertHu  阅读(1261)  评论(0编辑  收藏  举报