Click here to Skip to main content
15,846,727 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

I have three combo box in my .net windows application.In 1st combo box i have two option like India and Foreign. If i select india in 1st combo box,the third combo box will have to disabled. if i choose foreign in 1st combo box ,the 2nd combo box will have to disabled. This is my question.Kindly send me the coding.


C#
protected void combobox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(combobox1.SelectVelue == "indian")
{
combobox3.Enable = false;
combobox2.Enable = true;
}
else if (combobox1.SelectVelue == "Foreign")
{
combobox3.Enable = true;
combobox2.Enable = False;
}
Else
{
combobox3.Enable = true;
combobox2.Enable = true;
}
}



This code is not work..So please send any other..



Thanks,
Viswanathan.M
Posted
Updated 8-Jul-11 8:19am
v4

C#
switch (combo1.SelectedValue)
{
    case "India" : 
        combo3.Enabled = false;
        combo2.Enabled = true;
        break;
    case "Foreign" :
        combo3.Enabled = true;
        combo2.Enabled = false;
        break;
    default:
        combo3.Enabled = true;
        combo2.Enabled = true;
        break;
}


This is easily found on Google.
 
Share this answer
 
v3
Comments
Viswanthan.M. 8-Jul-11 12:15pm    
Thank you... one more doubt.. At what event i can write this code?
You as well archive this task using an if statement (Becasue your question is if combobox1 value == "india" the third combo box will have to disabled) and (If combobox1 value == "Foreign" 2nd combo box will have to disabled)

You can create a function to hold this and use it like this or just Double click the combo box from the designer view in your IDE

protected void combobox1_SelectedIndexChanged(object sender, EventArgs e)
{
if(combobox1.SelectVelue == "indian")
{
combobox3.Enable = false;
combobox2.Enable = true;
}
else if (combobox1.SelectVelue == "Foreign")
{
combobox3.Enable = true;
combobox2.Enable = False;
}
Else
{
combobox3.Enable = true;
combobox2.Enable = true;
}
}
 
Share this answer
 
v2
Comments
Viswanthan.M. 8-Jul-11 13:16pm    
Hi Mr.Ahmed

I tried this code.But its not working.Kindly help me.
Richard MacCutchan 8-Jul-11 15:26pm    
Please use <pre> tags when posting code snippets.

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