winform datagridview行头添加序号

1、使用datagirdview的RowPostPaint事件

2、datagirdview命名为dgv。(当然这个名字随意,开心就好)

3、贴代码

  private void dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            SolidBrush b = new SolidBrush(this.dgv.RowHeadersDefaultCellStyle.ForeColor);
            e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), this.dgv.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
        }
原文地址:https://www.cnblogs.com/bklsj/p/15091332.html