Add index numbers to each row header in a DataGridView


/ Published in: C#
Save to your folder(s)

`w_Dgv` is the name of the DataGridView control.


Copy this code and paste it in your HTML
  1. private void w_Dgv_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
  2. {
  3. // Add row numbers
  4. // Taken from "Pro C# 2008 and The .NET 3.5 Platform" pp. 807-808
  5. using (var brush = new SolidBrush(Color.Black))
  6. {
  7. e.Graphics.DrawString((e.RowIndex).ToString(),
  8. e.InheritedRowStyle.Font, brush, e.RowBounds.Location.X + 15,
  9. e.RowBounds.Location.Y + 4
  10. );
  11. }
  12. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.