Click here to Skip to main content
15,849,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two different tables in a mysql database.
table1       table2

option1      displaysthis1
option2      displaysthis2
option3      displaysthis3

If i choose option1 on combobox1 it should displaythis1 on comboxbo2 as an option. how could i do it?
This is how i filled the first combobox..
void Fillcombo() {
            string newcontact = "datasource=localhost;port=3306;username=root;password=password";
            string Query = "select * from database.clients ;";

            MySqlConnection addcon = new MySqlConnection(newcontact);
            MySqlCommand cmdDataBase = new MySqlCommand(Query, addcon);
            MySqlDataReader myReader;

                myReader = cmdDataBase.ExecuteReader();
                while (myReader.Read())
                    string sName = myReader.GetString("company");
            catch (Exception ex)
Updated 5-Aug-13 8:29am

1 solution

At first, fill the first combobox with data and then on selected index change of the first combobox fill the second one.
Share this answer
Raa_in 5-Aug-13 12:45pm    
the first combo box does have data i just dont know how to filter
Sergey Alexandrovich Kryukov 5-Aug-13 12:51pm    
It it does not have data, there is no a problem (nothing should happen, so the problem is solved). This answer is correct, follow the advice.
If something is not clear, ask a question, but a sensible one.
Sergey Alexandrovich Kryukov 5-Aug-13 12:51pm    
Short but to the point, 5ed.
Maciej Los 5-Aug-13 15:59pm    
Boipelo 5-Aug-13 12:55pm    
By filter you mean selecting the value? Use SelectedValue and use the selected value to load the second ComboBox with values matching that value. You database design is important to achieve this... How is your table design? Whats the fields?

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