I have a user control that contains 2 columns of TableLayoutPanel and accepts commands to dynamically add rows to display the details of the element selected in a separate control. Thus, the user will select a row in another control (DataGridView), and in the SelectedItemChanged event handler for the DataGridView, I clear the detail control and then regenerate all the rows for the new selected element (which may have completely different details displaying from the previously selected element) . This has been working fine for a while. But if I continue to move from one selected item to another for quite some time, updates become VERY slow (3-5 seconds each). It sounds like I'm not managing everything right, but I can't understand what I am missing. Here is my code to clear TableLayoutPanel:
private readonly List<Control> controls; public void Clear() { detailTable.Visible = false; detailTable.SuspendLayout(); SuspendLayout(); detailTable.RowStyles.Clear(); detailTable.Controls.Clear(); DisposeAndClearControls(); detailTable.RowCount = 0; detailTable.ColumnCount = 2; } private void DisposeAndClearControls() { foreach (Control control in controls) { control.Dispose(); } controls.Clear(); }
And as soon as I finish loading all the controls that I want in the TableLayoutPanel, for the next detailed display here, what I call:
public void Render() { detailTable.ResumeLayout(false); detailTable.PerformLayout(); ResumeLayout(false); detailTable.Visible = true; }
I use nothing but shortcuts (and TextBox very rarely) inside the TableLayoutPanel, and add shortcuts and text fields to the list of controls (link to DisposeAndClearControls ()) when I create them. I tried just iterating over the details. Controls and removes them in this way, but it seems that it skips half of the controls (determined by going through it to the debugger). So I know that I am all of them.
I would be interested in any suggestions for improving the performance of the drawing, but especially what caused the degradation of several options.
source share