Populating a Combobox based on another combobox value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • eihabisaac
    New Member
    • Aug 2007
    • 38

    Populating a Combobox based on another combobox value

    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
  • eihabisaac
    New Member
    • Aug 2007
    • 38

    #2
    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

    Comment

    • tlhintoq
      Recognized Expert Specialist
      • Mar 2008
      • 3532

      #3
      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 "SelectedIndexC hanged" 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.
      Code:
      		private void cbFirstComboBox_SelectedIndexChanged(object sender, EventArgs e)
      		{
      			switch (((ComboBox)sender).SelectedItem as string)
      			{
      				case "United States":
      					cbSecondComboBox.SelectedIndex = 1;
      					break;
      				case "Russia":
      					cbSecondComboBox.SelectedIndex = 2;
      					break;
      			}

      Comment

      Working...