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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:07:39+00:00 2026-05-27T12:07:39+00:00

I have a window form that has a couple of combo boxes. What I

  • 0

I have a window form that has a couple of combo boxes.
What I need accomplished is to have every combo box that has items to have their selected index set to 0. Rather than do every combo box by name manually, is there a function that returns all the children by type. Or to get all the children and compare their type to that of the combobox element?

@noah, your original code did not work at first, but all I needed was the reminder that the children are called controls (thanks).

With that I made a recursive function that sets all combo boxes not just the direct descendants of the main form:

private void recursiveSetComboBox(Control element)
{
    foreach (Control a in element.Controls)
    {
        if (a.Controls.Count != 0)
            recursiveSetComboBox(a);
        else if (a.GetType().Name == "ComboBox")
        {
            ComboBox b = (ComboBox)a;

            b.SelectedIndex = 0;
        }
    }
}

recursiveSetComboBox(this);
  • 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-27T12:07:40+00:00Added an answer on May 27, 2026 at 12:07 pm

    This is how I would do it:

    foreach (var comboBox in myForm.Controls.OfType<ComboBox>())
    {
        comboBox.SelectedIndex = 0;
    }
    

    If the combo boxes are not directly on the form but inside a container (group box, panel, etc.) then use that instead of myForm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i currently have a form that has several check boxes, once all the boxes
I have a window form application, and it has multiple threads running that would
I have a C# Windows Form Application that has settings, in the settings window
I have a Window.Form that has a WebBrowser control on it. How do you
I have a .NET powered website, that has a sign-up box form already. I'm
I have a windows form that has two DataGridViews (DGVs) that will hold 25,000+
I have a Windows application that has 2 Forms . From one form I
I have a Switch to window button on my main form that I'd like
I have a form (signup.php) that pops up in a nyroModal window when I
i have a windows form that contains a bunch of textboxes. I need a

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.