Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have combobox1 and comboox2 and in combobox1 my elements are A,B,C and combobox2 1,2,3,4,5,6...

A related 1,2,3 and B related 3,4 and C related 5,6.When I choose "A" I want to see just 1,2,3 ; when select "B" just 3,4 etc.

How can I imagine it ?

I tried to do in selected index changed but I didn't
Posted
Updated 24-Jul-12 2:06am
v2
Comments
dimpledevani 24-Jul-12 8:07am    
On selectionChangeCommitted event of first combobox,check if its a,b or c.According to it keep the required elements and remove the unrequired of second combobox
y.baris 24-Jul-12 8:25am    
I dont know how to remove unrequired of second combobox
OriginalGriff 24-Jul-12 8:08am    
What did you try to do in the SelectedIndexChanged event?
What happened? What didn't?
y.baris 24-Jul-12 8:26am    
I tried if A is clicked then I want to see just 1,2,3 propertys in combobox2 but I didn't...
or can you offer better solution ??
dimpledevani 24-Jul-12 8:32am    
combobox.items.remove(), search about this and you will find it

1 solution

Hello,

Try This:

C#
private void Form1_Load(object sender, EventArgs e)
{            
    comboBox1.Items.AddRange(new string[] { "A", "B", "C" });
    comboBox1.SelectedIndex = -1;
    comboBox2.Items.Clear();
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    comboBox2.Items.Clear();
    switch (comboBox1.SelectedItem.ToString())
    {
        case "A":
            comboBox2.Items.AddRange(new string[] { "1", "2", "3" });
            break;

        case "B":
            comboBox2.Items.AddRange(new string[] { "3", "4"});        
            break;

        case "C":
            comboBox2.Items.AddRange(new string[] { "5", "6" });    
            break;
        default:
            break;
    }
    comboBox2.SelectedIndex = -1;
}


Att.
Ernesto Fazolo
 
Share this answer
 
Comments
y.baris 24-Jul-12 8:59am    
Thanks for your solution Ernesto :)

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