Click here to Skip to main content
13,042,421 members (83,591 online)
Rate this:
Please Sign up or sign in to vote.
See more:

I have two comboboxes.
combobox1 values
combobox2 values

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...
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
     if (string.IsNullOrEmpty(comboBox4.Text))
           MessageBox.Show("From should not be empty");
           comp.FROM = Convert.ToInt32(comboBox4.Text);
     if (string.IsNullOrEmpty(comboBox5.Text))
           MessageBox.Show("To Should not be empty");
           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 16-Feb-13 8:27am
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.
Imtiyaz_mi 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?
Tadit Dash 17-Feb-13 7:35am
Please check the events related to combobox1 in the properties tab.
May be you have written comboBox2_SelectedIndexChanged inside the event OnSelectedIndexChanged of combobox1.
Shahare 17-Feb-13 7:40am
"when I select any value from any one of combobox, then that value automatically set into another combobox" - that does not sound OK - check your code if you set the value to the other combobox somewhere.
Sugihono Budiman 17-Feb-13 10:08am
Use requiredvalidator for combobox. So before postback it will alert user for empty combobox. Look at initialvalue to set the first value.
Why not use sql query to with WHERE value1 BETWEEN value2? this way let SQL does the heavy lifting for your UI

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100