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);
}
越努力,越幸运!
原文地址:https://www.cnblogs.com/hubbert123/p/10334147.html