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 15:45pm
Edited 9-Sep-12 15:46pm
Wes Aday94.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 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
0 OriginalGriff 240
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,180


Advertise | Privacy | Mobile
Web04 | 2.8.141216.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