Click here to Skip to main content
12,354,330 members (65,711 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Windows form
Hi I'm trying to get my comboBox to become visible once a certain item is selected in my listbox.
I have this code:

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

This isn't working... Any other ideas?
Posted 9-Sep-12 14:45pm
Edited 9-Sep-12 14:46pm
Wes Aday104.2K
v2
Comments
Wes Aday 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?
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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

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

Thanks!!!
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 10 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100