【转】c# winform datagridview Rowhead 添加 自增长编号

原文链接: https://blog.csdn.net/ohyoyo2014/article/details/38346887

RowPostPaint 事件:

       private void dgvData_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            //自动编号,与数据无关
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y, dgvData.RowHeadersWidth - 4, e.RowBounds.Height);
            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(), dgvData.RowHeadersDefaultCellStyle.Font, rectangle, dgvData.RowHeadersDefaultCellStyle.ForeColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }

 

你可能感兴趣的:(ASP.NET代码)