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.
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
SenthilkumarPosted Apr 13, 2012, 3:52 AM
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;
}
MementoPosted Apr 13, 2012, 5:28 AM