Click here to Skip to main content
15,886,095 members

combobox selected index changed event

baskaran chellasamy asked:

Open original thread
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 ?
Tags: C# (C# 4.0)

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900