0
点赞
收藏
分享

微信扫一扫

如何为datagridview加上序号

爪哇驿站 2022-06-30 阅读 231

​最简单的方法是在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);


}

  

举报

相关推荐

0 条评论