Click here to Skip to main content
15,884,975 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I'm trying to get my comboBox to become visible once a certain item is selected in my listbox.
I have this code:

C#
If(listBox.SelectedItems.Contains("Tea"))
{
    ComboBox.Visible = true;
}


This isn't working... Any other ideas?
Posted
Updated 9-Sep-12 14:46pm
v2
Comments
[no name] 9-Sep-12 20:49pm    
And "isn't working" means what exactly? The code is never called? SelectedItems never contains "Tea"? Combobox never becomes visible? The code ran and your hard drive melted?

Hello,
Move the code to click event it will work.

C#
private void listBox1_Click(object sender, EventArgs e)
{
 if (listBox1.SelectedItems.Contains("Tea"))
   comboBox1.Visible = true;
}


Thanks!!!
 
Share this answer
 
Sorry... When I run the program, and Tea is selected, the comboBox does not become visible.
However, if I change the code to
If(listBox.Items.Contains("Tea"))
{
ComboBox.visible = true;
}
And I select tea, the comboBox appears. But it appears even if I do not select tea.
 
Share this answer
 

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