Click here to Skip to main content
Rate this: bad
good
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 Aday87.3K
v2
Comments
Wes Aday at 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 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  
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  

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

  Print Answers RSS
0 OriginalGriff 392
1 CPallini 365
2 Sergey Alexandrovich Kryukov 348
3 BillWoodruff 264
4 George Jonsson 255
0 OriginalGriff 5,095
1 CPallini 4,285
2 Sergey Alexandrovich Kryukov 3,767
3 George Jonsson 2,941
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 10 Sep 2012
Copyright © CodeProject, 1999-2014
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