Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3406564
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:38:35+00:00 2026-05-18T05:38:35+00:00

I have a Panel I want to fill with some UserControl(s) at runtime. These

  • 0

I have a Panel I want to fill with some UserControl(s) at runtime. These controls are complex and may be interdependent, so I’d like them:

  • to be editable with Visual Studio designer;
  • to be in the same context (= defined in the same class);

Both of the requirements are a must-have.

Considering UserControl is itself an indexed collection of Control(s), I started designing my controls in the same class, without caring about real positioning of them (that will be specified runtime). I already used the same identical approach with DevComponents ribbon containers (with much satisfaction), so I initially thought the same was possible with standard UserControl(s).

I eventually realized that a Control can be inside only one Control.ControlCollection instance at a time, so I couldn’t use the Controls property and add controls to another panel without removing them from the original “dummy” UserControl.

My question is: is there a clean and supported way to create this designer-aware UserControl collection? I would call this approach a pattern because it really adds code clearness and efficiency.

Thanks,
Francesco

P.S.: as a workaround, I created a DummyControlContainer class that inherits UserControl and keeps a Dictionary map filled at ControlAdded event (code follows). Wondering if there’s something cleaner.

public partial class DummyControlContainer : UserControl
{
    private Dictionary<string, Control> _ControlMap;

    public DummyControlContainer()
    {
        InitializeComponent();

        _ControlMap = new Dictionary<string, Control>();
        this.ControlAdded += new ControlEventHandler(DummyControlCollection_ControlAdded);
    }

    void DummyControlCollection_ControlAdded(object sender, ControlEventArgs args)
    {
        _ControlMap.Add(args.Control.Name, args.Control);
    }

    public Control this[string name]
    {
        get { return _ControlMap[name]; }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:38:35+00:00Added an answer on May 18, 2026 at 5:38 am

    After testing and using it in a real world project, I’m more and more convinced that my solution was clean and safe if you need such a pattern. This container is intended to be filled with controls such as panels or similar. To prevent some bad behaviors with bindable data sources, I provided each new control added to this container with its own BindingContext. Enjoy.

    public partial class DummyControlContainer : UserControl
    {
        private Dictionary<string, Control> _ControlMap;
    
        public DummyControlContainer()
        {
            InitializeComponent();
    
            _ControlMap = new Dictionary<string, Control>();
            this.ControlAdded +=
                new ControlEventHandler(DummyControlCollection_ControlAdded);
        }
    
        void DummyControlCollection_ControlAdded(object sender,
            ControlEventArgs args)
        {
            // If the added Control doesn't provide its own BindingContext,
            // set a new one
            if (args.Control.BindingContext == this.BindingContext)
                args.Control.BindingContext = new BindingContext();
            _ControlMap.Add(args.Control.Name, args.Control);
        }
    
        public Control this[string name]
        {
            get { return _ControlMap[name]; }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have panel that is using group layout to organize some label. I want
I have an application where I'm adding controls during runtime and want to attach
I have a Panel filled with a lot of controls for users to fill.
I have a panel (bottom aligned) and some controls (client aligned). To animate the
I have panel and various controls on it. I would like to save an
i have a panel in another panel and i want to access an member
I have Panel with a BottomToolbar . I want to add and remove dynamically
I have a page that above it I want to have a panel that
I have created a Dynamic View Panel custom control and want to add a
I have items wrapped in wrap panel. I want to move first line of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.