给datagridview中添加序号(在datagrid中添加、在sql中添加)

在datagridview中添加

 private void dgvSummary_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
              SolidBrush b = new SolidBrush(this.dgvSummary.RowHeadersDefaultCellStyle.ForeColor);
              e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), this.dgvSummary.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20,         e.RowBounds.Location.Y + 4);
        }

  

在sql中添加

ROW_NUMBER() OVER (ORDER BY p.manfac ASC) AS id,

  

原文地址:https://www.cnblogs.com/leiminghui/p/13152355.html