Click here to Skip to main content
15,895,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I want a condition like

SQL
if(comboBox1.SelectedText = "Graduation")
                comboBox2.Items.Add("BA");


like this i have 5 options for comboBox1..Please tell me how to write the code..
Posted
Comments
choudhary.sumit 7-Dec-12 4:47am    
are you using any database?? in which this data is stored?
[no name] 7-Dec-12 4:48am    
no i m not using database..
i m adding like comboBox1.Items.add("Graduation")
like this..

C#
if(comboBox1.SelectedText = "Graduation")
                comboBox2.Items.Add("BA");
else if(comboBox1.SelectedText== "Gender")
                comboBox2.Items.Add("M/F");
else if(comboBox1.SelectedText== "Class")
                comboBox2.Items.Add("Maths/History");
// and so on...
 
Share this answer
 
Comments
[no name] 7-Dec-12 4:49am    
i did this but it's giving me error..Invalid expression term else and then expected semi-colon..
[no name] 7-Dec-12 4:53am    
Post your code...
[no name] 7-Dec-12 4:55am    
if (comboBox1.SelectedText == "10")
comboBox2.Enabled = false;

else if(comboBox1.SelectedText == "10+2")
comboBox2.Enabled = false;

else if(comboBox1.SelectedText == "Graduation")
comboBox2.Items.Add("BA");
comboBox2.Items.Add("BBM");
comboBox2.Items.Add("BCA");

else if(comboBox1.SelectedText == "Post-Graduation")
comboBox2.Items.Add("MA");
comboBox2.Items.Add("MBA");
comboBox2.Items.Add("MCA");

else if(comboBox1.SelectedText == "Doctorate")
comboBox2.Items.Add("M.tech");
comboBox2.Items.Add("P.hd");
SQL
if (comboBox1.SelectedText == "10")
                    comboBox2.Enabled = false;

             else if(comboBox1.SelectedText == "10+2")
                    comboBox2.Enabled = false;

            else  if(comboBox1.SelectedText == "Graduation")
{
                    comboBox2.Items.Add("BA");
                    comboBox2.Items.Add("BBM");
                    comboBox2.Items.Add("BCA");
}

            else if(comboBox1.SelectedText == "Post-Graduation")
{
                    comboBox2.Items.Add("MA");
                    comboBox2.Items.Add("MBA");
                    comboBox2.Items.Add("MCA");
}

            else if(comboBox1.SelectedText == "Doctorate")
{
                    comboBox2.Items.Add("M.tech");
                    comboBox2.Items.Add("P.hd");
}
 
Share this answer
 
Comments
[no name] 7-Dec-12 5:02am    
No..the data is not loading at the combo box2
Daskul 9-Dec-12 20:17pm    
Why do you want to add items on combobox2 when selectedIndex is changed? Everytime you changed the selection, combobox2 will have same entry of items.

Maybe you want to change the content of the combobox2 when combobox1 changes, and not adding same data each time you change selection on combobox1
Its workin :
C#
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
      {
          if ("Graduation" == comboBox1.SelectedItem.ToString())
          {
              comboBox2.Items.Add("BBM");
              comboBox2.Items.Add("BCA");
          }

          if ("Post-Graduation" == comboBox1.SelectedItem.ToString())
          {
              comboBox2.Items.Clear();

              comboBox2.Items.Add("MA");
              comboBox2.Items.Add("MBA");
              comboBox2.Items.Add("MCA");
          }
      }
 
Share this answer
 
Comments
MT_ 7-Dec-12 5:26am    
Hey...Don't keep posting as new solution. You can use "Improve Solution" to update your solution. This will simply distract OP and other users coming to this thread.
[no name] 7-Dec-12 5:28am    
Okay.. Next time I'll be careful...
MT_ 7-Dec-12 5:42am    
Kool

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