title: How to populate a combo box from another combo box in the same form?
body: <p>Two comboBox and a table called MAINCATE is created.</p>
  
  <p>I have a code , but stuck to determine what SQLQuery should i use to get the second combo box filled , determined by the first combo box.</p>
  
  <p>I just need a little help on how to fill in the second combobox based on mainCate picked by the first combobox..</p>
  
  <p>i need to do something like.. if combobox 1 mainCate is "Food" , then combo box 2 should show "Raw , cooked , fruits and vegetables"</p>
  
  <p>This is what is inside of the MAINCATE table - 
  (<a href="http://i.imgur.com/qR90Z2B.png" rel="nofollow">http://i.imgur.com/qR90Z2B.png</a>)</p>
  
  <p>And this is my code :-</p>
  
  <pre><code>DataSet ds1;
  DataSet ds2;
  
  public User()
  {
      InitializeComponent();
  }
  
  private void User_Load(object sender, EventArgs e)
  {
  
      SqlConnection conn = new SqlConnection();
      conn.ConnectionString = "Data Source=PEWPEWDIEPIE\\SQLEXPRESS;Initial Catalog=master;Integrated Security=True";
      conn.Open();
  
      SqlDataAdapter daMain = new SqlDataAdapter("SELECT * FROM MAINCATE", conn);
      ds1 = new DataSet();
      daMain.Fill(ds1, "Maincate");
      mainCatU.DisplayMember = "mainCate";
      mainCatU.ValueMember = "mainCate";
      mainCatU.DataSource = ds1.Tables["MAINCATE"];
      mainCatU.DropDownStyle = ComboBoxStyle.DropDownList;
      mainCatU.Enabled = true;
  
      SqlDataAdapter daSub = new SqlDataAdapter("SELECT &gt;What should i do here?&lt;", conn);
      ds2 = new DataSet();
      daSub.Fill(ds2, "Subcate");
      subCatU.DisplayMember = "Subcat1";
      subCatU.ValueMember = "Subcat";
      subCatU.DataSource = ds2.Tables["MAINCATE"];
      subCatU.DropDownStyle = ComboBoxStyle.DropDownList;
      subCatU.Enabled = true;
      conn.Close();
  }
  
  private void mainCatU_SelectionChangeCommitted(object sender, EventArgs e)
  {
      //have no idea if a code should be here..
  }
  </code></pre>
  
  <p>or should i do something like this?</p>
  
  <pre><code>SqlCommand cmd = new SqlCommand("select Subcat1,Subcat2,Subcat3,Subcat4 from MAINCATE where mainCate=@mainCate;", con);
  </code></pre>
  
  <p>=========================================</p>
  
  <p>@philip -
  putting this on page load repalcing my code above - it didnt work..</p>
  
  <pre><code>string result = mainCatU.SelectedItem.ToString();
  
              SqlDataAdapter daSub = new SqlDataAdapter("SELECT * FROM MAINCATE where mainCate = " + result , conn);
              ds2 = new DataSet();
              daSub.Fill(ds2, "Subcate");
              subCatU.DisplayMember = "Subcat1";
              subCatU.ValueMember = "Subcat1";
              subCatU.DataSource = ds1.Tables["MAINCATE"];
              subCatU.DropDownStyle = ComboBoxStyle.DropDownList;
              subCatU.Enabled = true;
  </code></pre>
  
  <p>even tried</p>
  
  <pre><code>SqlDataAdapter daSub = new SqlDataAdapter("SELECT * FROM MAINCATE where mainCate=@result", conn);
  </code></pre>