Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0
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 9:27am
Edited 17-Feb-13 2:15am
(no name)114.4K
José Amílcar Ferreira Casimiro at 16-Feb-13 15:20pm
Can you put all your class code here ?
Sergey Alexandrovich Kryukov at 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 at 17-Feb-13 3:23am
provide us the html code to see how you have designed your combobox controls.
Orcun Iyigun at 17-Feb-13 7:33am
Can you check if you bind your combobox1's selectedindexchangedevent to combobox2's?
Tadit Dash at 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 at 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 at 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
0 OriginalGriff 381
1 Sergey Alexandrovich Kryukov 245
2 Marcin Kozub 225
3 Praneet Nadkar 217
4 /\jmot 189
0 OriginalGriff 8,284
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,614
3 Maciej Los 4,989
4 Manas Bhardwaj 4,986

Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2014
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