Click here to Skip to main content
15,665,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have dynamically created a panel with multiple textboxes and checkboxes within it.
This panel gets added to a flow layout panel where there are multiple other panels just like it. At run time the user can add and remove these panels as needed.
The way that I am now getting and setting the controls is extremely inefficient.
This form pulls from many data sources. SQL connections, postgres connections,datatables. There has to be a better way.

I think I have two options. Create a custom control or inherit from panel

However, I have been at it for a few days and I cant seem to be able to create those in a way that allows me to just reference the inner controls i.e. textboxHours.Text = "hello";

please see image of control here


What I have tried:

Sometimes I can do controls.find which helps a little, but most of the time find myself looping through the entire flowlayout panel and matching a string.
Updated 6-Dec-21 19:29pm

1 solution

Even if you create a UserControl - and that's probably the way I would go if you need more than one panel with the same control set on it - you will have to find the appropriate "container" each time you want to access it.

So what I'd do is create a collection of Panel (or MyUserControl) objects and each time I add one to my form, I'd add it to the collection. If you use a Dictionary with a string Key, you can move directly to the relevant control just using teh string you are currently searching for.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900