Reputation: 4089
I am using TableLayoutPanel
in C# (Forms).
My table is pretty big with its 33 columns and 8 rows. All cells contain Label
-objects.
I have already set DoubleBuffered = true;
of my TableLayoutPanel by creating a new subclass:
public class DoubleBufferedTableLayoutPanel : TableLayoutPanel
{
public DoubleBufferedTableLayoutPanel()
{
DoubleBuffered = true;
}
}
If a user presses button X, all cell-controls are deleted and other labels are loaded into the table (from an array which contains all Label objects).
DEL: this.table.Controls.Remove(this.table.GetControlFromPosition(col, row));
ADD: this.table.Controls.Add(this.labelArray[row, (col+pos)], col, row);
Everything works fine, except that the progress of deleting the controls and adding the new ones takes five to ten seconds.
Is there a way other than to set DoubleBuffered = true
in order to speed up this process?
Upvotes: 3
Views: 3612
Reputation: 11
Try this code
TableLayoutPanel.GetType().GetProperty("DoubleBuffered",
System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)
.SetValue(TableLayoutPanel, true, null);
Upvotes: 1
Reputation: 31
Use this code to avoid the slow processing of events in C#
tableLayoutPanel1.Visible = false;
tableLayoutPanel1.Controls.Clear();
tableLayoutPanel1.SuspendLayout();
// Processing Code
tableLayoutPanel1.ResumeLayout();
tableLayoutPanel1.Visible = true;
Upvotes: 3
Reputation: 814
Are you getting the Data from the database to populate the tablelayoutpanel everytime you perform an action (postback)?
If so, consider lazy loading the data in to a bindable object once when the page first loads. Then use the populated object when re binding (on Postback).
Upvotes: 0
Reputation: 2785
I may be wrong but this sounds like a job for a datagridview, which is optimised for these tasks.
Upvotes: 0