tags:

views:

12

answers:

1

Hi Fellas, Can anyone help me by telling how to reduce the time of adding rows and colums to tablelayoutpanel dynamically? As 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 bad of my logic is Its taken considerable time in adding rows and columsn to tablelayoutpanel.

Plz guide

Regards Asad


    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;
        }
    }
+2  A: 

The best/only way to speed it up is by surrounding the changes with Suspendlayout/ResumeLayout.

Henk Holterman
Could you please further elaborate it? Its new to me 'Suspendlayout/Resume:ayout.
Asad
@Asad: just call yourtable.Suspendlayout() before changing the table and ResumeLayout() after it.
cevik