There are many questions concerning this issue here, but I have tried the solutions posted and still don’t get it to work.
I have a datagridview where I want to show the rownumber on the row headers.
This is what I have tried:
gridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
gridView.AutoResizeRowHeadersWidth(
DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders);
foreach (DataGridViewRow row in gridView.Rows)
{
row.HeaderCell.Value = (row.Index + 1).ToString();
}
This code is called from the OnLoad event, since in other questions it is stated that the code should not be run in the constructor.
Advice? Thanks!
I think my approach would be to bind a row on the ItemDataBound event rather than going over the rows all a single place. Something along the lines of: