I have a DataGridView and I need to add several (say 20) columns to it dynamicly. When I do it like this
foreach (var columnName in ColumnNames)
dataGridView.Columns.Add(columnName, columnName);
horizontal scroll bar tries to stay up to date every time new column is added. So user sees strange scroll bar shrinking. I need to update horizontal scroll bar only once when all columns are added. How do I accomplish this?
P.S. I tried to do it like this:
((System.ComponentModel.ISupportInitialize)(dataGridView)).BeginInit();
dataGridView.SuspendLayout();
foreach (var columnName in ColumnNames)
{
dataGridView.Columns.Add(columnName, columnName);
}
((System.ComponentModel.ISupportInitialize)(dataGridView)).EndInit();
dataGridView.ResumeLayout(false);
but it didn't help.