Click here to Skip to main content
16,010,114 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have two comboboxes.
combobox1 values
1000
1001
1002
1003
1004
combobox2 values
1000
1001
1002
1003
1004

Now I want to select data from database based on the two combobox value.

For example combobox1 = 1001 and combobox2=1004, then I need to select data between these two values.
Actually I wrote code to get value from database.

The code for combobox2_selectedindexchange event is...
C#
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
     if (string.IsNullOrEmpty(comboBox4.Text))
     {
           MessageBox.Show("From should not be empty");
     }
     else
     {
           comp.FROM = Convert.ToInt32(comboBox4.Text);
     }

     if (string.IsNullOrEmpty(comboBox5.Text))
     {
           MessageBox.Show("To Should not be empty");
     }
     else
     {
           comp.TO = Convert.ToInt32(comboBox5.Text);            
     }
     
     DataTable result = inter.getapplicationinformationstage1(comp);
     dataGridView1.DataSource = result;
}

But when I select data from combobox1, it automatically calls the event even I am not selecting the combobox2 value and when I select any value from any one of combobox, then that value automatically set into another combobox.
How can solve this ?
Posted
v2
Comments
José Amílcar Casimiro 16-Feb-13 15:20pm    
Can you put all your class code here ?
Sergey Alexandrovich Kryukov 16-Feb-13 19:32pm    
This is all pretty easy, but you should tell us the type of ComboBox; there are different similar but unrelated types named like that.
—SA
mimtiyaz 17-Feb-13 3:23am    
provide us the html code to see how you have designed your combobox controls.
Orcun Iyigun 17-Feb-13 7:33am    
Can you check if you bind your combobox1's selectedindexchangedevent to combobox2's?
Please check the events related to combobox1 in the properties tab.
May be you have written comboBox2_SelectedIndexChanged inside the event OnSelectedIndexChanged of combobox1.

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