c#, winform.
How to set default datagridview columns width for all collumns at once, not one by one.
I have over 50 columns and all of them should be width = 30.
How to set DataGridView default Columns Width?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.


SenthilkumarRank #387 · 6.5K reputationPosted Apr 12, 2012, 11:52 PM EDT
You can do it by like this.
for (int i = 0; i < DataGridView1.Columns.Count; i++)
{
DataGridView1.Columns[i].Width = 30;
}
or you can write the event
dataGridView1.ColumnAdded += new DataGridViewColumnEventHandler(dataGridView1_ColumnAdded);
void dataGridView1_ColumnAdded(object sender, DataGridViewColumnEventArgs e)
{
e.Column.Width = 30;
}
Memento104 reputationPosted Apr 13, 2012, 1:28 AM EDT