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 9001711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:28:22+00:00 2026-06-16T00:28:22+00:00

i can iterate through the controls which are on panel by this two code

  • 0

i can iterate through the controls which are on panel by this two code

       Form4 fl = new Form4();
       StringBuilder sb = new StringBuilder();
       foreach (Control c in panel1.Controls)
       {
           if (c is ComboBox)
           {
               ComboBox cb = (ComboBox)c;
               sb.Append(cb.Text);
               fl.comboBox1.Text = sb.ToString();
               fl.Show();
           }

       } 

OR by this
List lst = new List();
void GetComboBoxValues()

    StringBuilder sb = new StringBuilder();
    {
      sb.Append(c.Text + "\r\n");
    }
   MessageBox.Show(sb.ToString());
     }

but i add a panel and on panel a usercontrol which contains a combobox and textbox how that can be possible to find controls and add to the string builder
so i thought iterating through usercontrol and finding the text and adding it to the string builder,is that possible?

  • 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-06-16T00:28:23+00:00Added an answer on June 16, 2026 at 12:28 am

    Responding to the comment left for L.B’s answer. Personally I believe L.B’s answer is the easiest and requires the least amount of coding, the best thing is it will find all the controls of a specific type on a panel no matter how nested they are(imagine if you have a user control inside a user control).

    Just copy the FindControls method from LB’s answer to your solution as is and where you need to loop through the controls of the panel, do something like this:

    StringBuilder sb = new StringBuilder();
    var comboBoxes = FindControls<ComboBox>(panel1).ToList();
    var textBoxes = FindControls<TextBox>(panel1).ToList();
    
    foreach (var comboBox in comboBoxes)
        sb.AppendLine(comboBox.SelectedItem.ToString());
    
    foreach (var textbox in textBoxes)
        sb.AppendLine(textbox.Text);
    
    MessageBox.Show(sb.ToString());
    

    A simple example would be something like this, but be warned that it will not work if you have a case of a user control inside a user control, so I would strongly suggest going with LB’s example:

        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < panel1.Controls.Count; i++)
        {
            if (panel1.Controls[i].Controls.Count > 0)
            {
                //Iterate through the controls in the user control
                foreach(Control c in panel1.Controls[i].Controls)
                {
                }
            }
            else
            {
                //Handle the controls with no children
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using .NET 2.0. How can I iterate through all controls of a
How can iterate through an NSString object in Objective c whiling maintaining an index
I'm trying to iterate through all nodes, so I can print them out for
I have a list of questions that the user will iterate through, they can
I know that I can iterate over an object's properties like this: for (property
How can I iterate ResultSet ? I've tried with the following code, but i
I'm trying to iterate through the controls on a form to display the ControlSource
With DataMapper i can iterate through properties and select one(s) of type Serial .
Basic requirement is to know if we can iterate through $_POST when the request
I'm trying to figure out how I can iterate in reverse, and forward through

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.