Craig
Craig

Reputation: 103

C# winform removing and then adding more items to a panel control

Using C# Winforms, I have a panel that is to display some custom controls. I can add instances of the controls to the panel and if there are too many, the panel will scroll them.

myPanel.Controls.Add(myControl);

The issue comes after I start removing items from the panel. I am using:

myPanel.Controls.Remove(myControl);
myControl.Dispose();

however when I then go to add more controls to the panel, the new ones added will not display at all.

myPanel.Controls.Add(newControl);

newControl or any subsequent controls will not be visible.

Can anyone assist with this please, thank you in advance.

Upvotes: 8

Views: 6914

Answers (1)

Developer
Developer

Reputation: 8634

You are not clearing your panels. Try this:

mypanel.Controls.clear();

Upvotes: 8

Related Questions