当前位置:首页 > Windows程序 > 正文

【转】DataGridView之为每行前面添加序号

2021-03-28 Windows程序

//最简单的方法是在Datagridview的事件RowPostPaint事件下面添加如下代码即可 private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { SolidBrush b = new SolidBrush(this.dataGridView1.RowHeadersDefaultCellStyle.ForeColor); e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), this.dataGridView1.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4); }

温馨提示: 本文由Jm博客推荐,转载请保留链接: https://www.jmwww.net/file/69064.html