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

  • Home
  • SEARCH
  • 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 125899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:13:56+00:00 2026-05-11T05:13:56+00:00

I am attempting to write a ‘User Control’ in WinForms .NET (not ASP.NET). The

  • 0

I am attempting to write a ‘User Control’ in WinForms .NET (not ASP.NET). The control is relatively simple. It will contain a label, a button, and a DataGridView.

However, the control needs to be able to instantiate itself, i.e. when the user clicks the button (of the parent control) at least 1 nested (children) control of the same type will be displayed underneath (kind of like a Tree)

I am having no success writing such a recursive control using a ‘User Control’. A StackOverflow Exception occurs when instantiating MyControl within it’s own constructor.

Therefore, I am leaning towards using a ‘Custom Control’, hoping it can handle the instantiation of itself (maybe in the Paint event??). Alot more work has to go into a Custom Control however, so I don’t want to go down this path if it’s going to take forever. I am on a tight deadline.

Anybody done this using a Custom Control or have any solid ideas on how to create a recursive control?

By the way, this control would be used in a fairly finite number of recursive combinations, so maybe it would be better to create a separate control for each parent/children scenario? I am thinking that would result in at least 10 separate user controls.

thanks for your help

UPDATE (here is my initial attempt at a stop condition per your feedback, but this is still causing children to be created indefinitely) :

  public partial class CustomX : UserControl     {         private IList _children = new List();          public CustomX()         {             InitializeComponent();              Recurse(0);          }          private void Recurse(int childCount)         {             if (childCount  
  • 1 1 Answer
  • 1 View
  • 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. 2026-05-11T05:13:56+00:00Added an answer on May 11, 2026 at 5:13 am

    The problem is probably that the child control also instantiates a child control. There has to be a stop condition or controls will be generated until the stack overflows.

    This should work:

    public partial class CustomX : UserControl     {         private IList _children = new List();          public CustomX(int depth)         {             InitializeComponent();             if(depth > 0)             {                 CustomX child = new CustomX(depth-1);                 this.Controls.Add(child)             }         }     } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 123k
  • Answers 123k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Solution: There was a general css setup for the image… May 12, 2026 at 1:11 am
  • Editorial Team
    Editorial Team added an answer Yes, it'll work fine. Since so many other answers go… May 12, 2026 at 1:11 am
  • Editorial Team
    Editorial Team added an answer I ran into the same problem. I'd created a web… May 12, 2026 at 1:11 am

Related Questions

I am attempting to write a one-line Perl script that will toggle a line
I am attempting to write a component in C# to be consumed by classic
I am attempting to write a .NET component. The component will be dropped onto
I am attempting to write a 'User Control' in WinForms .NET (not ASP.NET). The
I am attempting to write a dynamic dispatcher for a function that's templated on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.