Related to: C#; Windows form, Storing Multiple Instances of a User Control:

Hi:

I’ve created an app with a user control that accepts parameters. When a user clicks a button I need to store the current view of the control and bring into focus on demand. Several instances of the UC need to be stored with different parms. Is a generic collection the best way to do this?

Thanks.

Try using a List<T> of the control.

Try using a List<T> of the control.

Thanks. That worked perfectly. Here’s what I did—just to test:
• Created user control with 3 textboxes, and 3 string parameters in the constructor.
• Created a form with a button, tab panel, and List<T> for the user control.
• On form load, created 10 instances of the user control, passing 3 unique string parameters. The user control then set the values in the textboxes. Added each instance to the List<T>.
• The purpose is now to display each instance on demand in the tab panel. The button click event “rotated” thru the List<T> of user control instances and added it to the panel with the textbox values properly displayed. Worked great. Only thing though, I disposed the control (from the tab panel) before adding the next instance. Once disposed, it’s no longer is available in the List<T>. I need all instances kept alive in the background, so I’ll try a different approach when removing from the tab panel.

Thanks Again,
ventura1

Simply adjusting the .Visible property should allow you to hide the controls without disposing of them.

Simply adjusting the .Visible property should allow you to hide the controls without disposing of them.

Yes thanks - I'll use that approach.