title: C# combobox options dependent on another combobox
body: <p>I am working on a program in which a combobox's options are dependent on another combobox's selected option.  The selected item from the first combobox chooses which options are in the second combobox.  Does anyone know how to do this?</p>
  
  <p>This is the button that adds the information to the first combobox</p>
  
  <pre><code>    try
          {
              CustomerAccount aCustomerAccount = new CustomerAccount(txtAccountNumber.Text, txtCustomerName.Text,
              txtCustomerAddress.Text, txtPhoneNumber.Text);
              account.Add(aCustomerAccount);
  
              cboClients.Items.Add(aCustomerAccount.GetCustomerName());
              ClearText();
          }
          catch (Exception)
          {
              MessageBox.Show("Make sure every text box is filled in!", "Error", MessageBoxButtons.OK);
          }
  </code></pre>
  
  <p>And here is the selectedIndex for the first combobox.  </p>
  
  <pre><code> private void cboClients_SelectedIndexChanged(object sender, EventArgs e)
      {
  
          CustomerAccount custAccount = account[cboClients.SelectedIndex] as CustomerAccount;
          if (custAccount != null)
          {
              txtAccountNumberTab2.Text = custAccount.GetAccountNumber();
              txtCustomerNameTab2.Text = custAccount.GetCustomerName();
              txtCustomerAddressTab2.Text = custAccount.GetCustomerAddress();
              txtCustomerPhoneNumberTab2.Text = custAccount.GetCustomerPhoneNo();
          }
      }
  </code></pre>