C# datagridview 前面加行号

2017-11-21  本文已影响0人  a9b854aded01
image.png

事件:

this.View.DgvGra.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(DgvGradeInfoRowPostPaint);

方法

 private void DgvGradeInfoRowPostPaint(object sender, System.Windows.Forms.DataGridViewRowPostPaintEventArgs e)
        {
            System.Drawing.Rectangle rectangle = new System.Drawing.Rectangle(e.RowBounds.Location.X,
                e.RowBounds.Location.Y,
                this.View.DgvStorageInfo.RowHeadersWidth - 4,
                e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
                this.View.DgvStorageInfo.RowHeadersDefaultCellStyle.Font,
                rectangle,
                this.View.DgvStorageInfo.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }
上一篇 下一篇

猜你喜欢

热点阅读