天天看點

C#datagridview加行号

C#datagridview加行号

  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 + 10, e.RowBounds.Location.Y + 4);

        }