The source code below demonstrates how to extend the DataGridView class so row numbers will automatically appear in the row header cells. In this implementation, the width of the column that contains the row header cells is automatically adjusted to accomodate the row numbering.
Here are a few screenshots of this class in action:
![]() |
![]() |
| Figure 1. The appearance of the row numbering in a custom DatagridView with 20 columns and 20 rows. | Figure 2. The appearance of the row numbering in a custom DatagridView with 20 columns and 1000 rows. This example also shows the appearance of the grid when a row is selected. |

