Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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...
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 16-Feb-13 8:27am
Edited 17-Feb-13 1:15am
105.3K
v2
Comments
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.
—SA
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 Sergey Alexandrovich Kryukov 881
1 OriginalGriff 270
2 Volynsky Alex 205
3 CPallini 180
4 Richard Deeming 175
0 OriginalGriff 5,640
1 Sergey Alexandrovich Kryukov 4,693
2 CPallini 4,540
3 George Jonsson 3,132
4 Gihan Liyanage 2,445


Advertise | Privacy | Mobile
Web02 | 2.8.140916.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