-1

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

Guilherme Fidelis
  • 1,022
  • 11
  • 20
alireza25
  • 13
  • 2

2 Answers2

1

you need to handle the OnRowDataBound event of your gridview.

protected void dataGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[YourColumnIndex].With = YourValue;
            }
        }
Guilherme Fidelis
  • 1,022
  • 11
  • 20
0

You have to set an appropriate DataGridViewRowHeadersWidthSizeMode value to RowHeadersWidthSizeMode.

For example:

dataGridView1.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.AutoSizeToAllHeaders;
jhmt
  • 1,401
  • 1
  • 11
  • 15