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

The Archive Base Latest Questions

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

Based on comboBox1 selection, I populate comboBox2. The comboBox2 has a variable quantity of

  • 0

Based on comboBox1 selection, I populate comboBox2. The comboBox2 has a variable quantity of list items. Currently I am doing this manually like this:

string[] str1 = { "item1", "item2" }
string[] str2 = { "item1", "item2", "item3" , "item4" }

etc.

if (cbox1.SelectedIndex == 0)
{
       cbox2.Items.AddRange(str1);
}
if (cbox1.SelectedIndex == 1)
{
       cbox2.Items.AddRange(str2);
}

etc.

Although this works, I have events for 4 drop downs and 13 possible choices for each. This makes for a lot of if’s. I would prefer to do this with an array of strings so that I can get rid of all of the if’s and just do the following for each SelectedIndexChanged:

cbox2.Items.AddRange(str[cbox1.SelectedIndex]);

but I am not sure if I can do this with the variable lengths of the strings. I get errors when doing:

string[,] str = { { "Item1", "Item2"},{"Item1", "Item2", "Item3", "Item4"} };

Is there a way to do this?

Thanks!

  • 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:05:34+00:00Added an answer on May 27, 2026 at 12:05 pm

    You have already discovered that you cannot use a multidimensional array in this situation, because your arrays have different lengths. However you could use a jagged array instead:

    string[][] str =
    {
        new string[] { "Item1", "Item2" },
        new string[] { "Item1", "Item2", "Item3", "Item4" }
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a combobox, and based on the current selection, I would like dynamic
Are there any professional Combobox controls (dropdown list with autosuggestion) based on the jQuery
Based on the response to this question: Why does C++ have header files and
Based on this question it appears that the default template for CheckStyle will allow
Based on this question I don't want to litter my ready stuff waiting for
I'm currently working on a membership system for my web application, which is based
Windows explorer in XP will allow you to make a file selection based on
I am coding a pyGTK application, and I'd like to change an input based
I want to populate the combobox dynamically based on the data I received from
I have three ComboBoxes such that C's items list is dependent on the selected

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.