Hello.
I do the program - SpreadSheet (similar to Excel). You need to number the rows in the DataGridView.

But since storing data in control is a bad idea; it was decided to use a DataTable instance for a DataGridView as a data source (DataSource property).
private DataTable table; //....... table = new DataTable(); DataGridView.DataSource = table; But if the column numbering is supported by both the DataGridView and the DataTable, and there are no problems with this, I could only find the line numbering in the DataGridView. It is necessary to make the usual numbering of lines as in Excel (1, 2, 3, ...). I did not find a similar code for DataTable:
rows = DataGridView.RowCount; for (int i = 0; i < rows; i++) { DataGridView.Rows[i].HeaderCell.Value = (i + 1).ToString(); // i+1 потому, что нумерация нужна } // с еденицы, а не с нуля Does DataTable really not support rowing? If supported, how to do it? If it doesn’t support, which data source for the DataGridView is better to use?
PS When using DataTable as a data source, for some reason it is impossible to number the DataGridView directly, as in the code above. Although without using DataTable, line numbering works fine. No error, no warning, the code simply does not lead to anything, as if nothing was numbered.