Reputation: 541
I am interested in reducing the time of adding rows and colums to tablelayoutpanel dynamically.
I need to add 10 rows and 10 columns (maximum 10x 10 =100 controls, may be less than 100 depending upon user input), I have construct the logic which works good but the problem of my logic is it's taken considerable time in adding rows and columns to tablelayoutpanel.
for (int rowNumber = 1; rowNumber <= (TSegments.Value); rowNumber++)
{
for (int columnNumber = 1; columnNumber < (PSegments.Value) * 2 + 2; columnNumber++)
{
tempTextBox = new TextBox();
tableLayoutPanel1.Controls.Add(tempTextBox, columnNumber, rowNumber);
tempTextBox.Anchor = System.Windows.Forms.AnchorStyles.Right;
tempTextBox.Dock = DockStyle.Fill;
}
}
Upvotes: 0
Views: 143
Reputation: 273274
The best/only way to speed it up is by surrounding the changes with Suspendlayout/ResumeLayout. Just call yourtable.Suspendlayout() before changing the table and ResumeLayout() after it.
Upvotes: 2