Click here to Skip to main content
15,895,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
im trying to make a combobox filter depending from another combobox. its from two different tables in the same database. comboBox2 is already filled from type table. the next should display another value dpending on what you selected in the first combobox

this is the code for the combobox


MySqlConnection con = new MySqlConnection("datasource=localhost;port=3306;username=root;password=Deprisa!79849;");
       private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
       {
           //comboBox2,3,and 9
           comboBox3.SelectedIndex = -1;
           comboBox3.Items.Clear();
           if (con.State == ConnectionState.Closed)
           {
               con.Open();
           }

           MySqlCommand cmd = new MySqlCommand("Select Distinct(idbrand) from machine where idtype='" + comboBox2.SelectedItem + "'", con);

           MySqlDataReader rd = cmd.ExecuteReader();
           while (rd.Read())
           {
               comboBox3.Items.Add(rd[0]);
           }

           rd.Close();
           cmd.Dispose();



       }

       private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
       {
           comboBox9.SelectedIndex = -1;
           comboBox9.Items.Clear();

           if (con.State == ConnectionState.Closed)
           {
               con.Open();
           }

           MySqlCommand cmd = new MySqlCommand("select idmodel from machine where idtype='" + comboBox2.SelectedItem + "' and idmodel = '" + comboBox3.SelectedItem + "'", con);

           MySqlDataReader rd = cmd.ExecuteReader();

           while (rd.Read())
           {
               comboBox9.Items.Add(rd[0]);
           }
           rd.Close();
           cmd.Dispose();
       }
Posted

1 solution

So what is your question ? and what is the error you are getting ?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900