By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,751 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

Populating a Combobox based on another combobox value

P: 38
Hi everyone

I'm using VS2005 C# with MySQL to do a windows application

i'm also using Devart for MySQL

i was able to populate a combobox from the database

but i really want to populate the other combobox based on the first combo value

like the picture

such as Ajax

can anybody help me
Feb 27 '09 #1
Share this Question
Share on Google+
2 Replies

P: 38
hi all

23 View for now and nobody knew how to do that
i did and im not gonna tell you how ,, just kidding i will post it later
Feb 28 '09 #2

Expert 2.5K+
P: 3,525
I see this come up a LOT. I'm very surprised that when you do a search on Google or through Bytes that you don't find a dozen questions just like it over the last few weeks or months. Just because the answer is a couple months old doesn't make it any less valid.

Just react to the "SelectedIndexChanged" event of the first combo box. If the selected index is -1, then no item is selected. zero or greater is the index of the Items array. One way to handle it could be to create a Switch...Case construct.
Expand|Select|Wrap|Line Numbers
  1.         private void cbFirstComboBox_SelectedIndexChanged(object sender, EventArgs e)
  2.         {
  3.             switch (((ComboBox)sender).SelectedItem as string)
  4.             {
  5.                 case "United States":
  6.                     cbSecondComboBox.SelectedIndex = 1;
  7.                     break;
  8.                 case "Russia":
  9.                     cbSecondComboBox.SelectedIndex = 2;
  10.                     break;
  11.             }
Feb 28 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.