Search code examples
c#asp.netdatagridviewcolumn

Changing width of a column from gridview


I with this code marking the first column from DataGridView:

for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
    dataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString();
}

but because the low width, the numbers are not shown properly, how can I change the width the first column ?

Image:

enter image description here


Solution

  • You have to set an appropriate DataGridViewRowHeadersWidthSizeMode value to RowHeadersWidthSizeMode.

    For example:

    dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;