title: How can I do an hierarchy using 3 combo boxes in C# and SQL Server?
body: <p>I have 3 combo boxes that use a data source obtained from a SQL Server Express table and they are linked with each other. For example:</p>
  
  <p>combo box 1 = university (oxford, cambridge);
  combo box 2 = course (biology, computer science); combo box 3 = classes (algorithms, database)</p>
  
  <p>when the user chooses "oxford" in combo box 1, then only the courses of oxford must appear in combo box 2 (lets suppose biology and computer science); then, when the user chooses the course, only the classes of that specific course must appear in combo box 3.</p>
  
  <p>the problem is: when the user changes the university that have been chosen before, the data source of the other 2 combo boxes aren't following the right way.... I'm using the combo box event called "selected index changed"</p>
  
  <p>when the user selects another option in combo box 1, it triggers the event of changing combo box 1, then combo box 2 is updated, but before it shows the correct option inside it, it triggers the event of changing its index and then combo box 3 tries to update using the wrong infos about combo box 2... making a mess </p>
  
  <pre><code>    private void comboBoxUniversity_SelectedIndexChanged(object sender, EventArgs e)
      {
          comboBoxCourse.DataSource = valuesComboBoxes.GetCourse(comboBoxUniversity.Text);
          comboBoxCourse.DisplayMember = "name_Course";
          comboBoxCourse.Update();
      }
  
      private void comboBoxCourse_SelectedIndexChanged(object sender, EventArgs e)
      {
          comboBoxClasses.DataSource = valuesComboBoxes.GetClasses(comboBoxUniversity.Text, comboBoxCourse.Text);
          comboBoxClasses.DisplayMember = "name_Classes";
          comboBoxClasses.Update();
      }
  </code></pre>