2 Attachment(s)
[RESOLVED] How do I use a combobox to make images and labels visible or hidden
Hi, So Basically what I am currently trying to is use a Combobox to change make labels and images either .Show() or .Hide()
These are the item's I have within my ComboBox
Attachment 179842
Let's say I choose the Liverpool item in the combo box like this, how could I get it so it would .show() the labels and image when I have it selected.
Attachment 179843
This is the code I currently have:
Private Sub BookAPod_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Hiding Images and Text until chosen in list box
lblLiverpoolPod.Hide()
lblManchesterPod.Hide()
lblLondonPod.Hide()
PictureBoxLiverpool.Hide()
PictureBoxManchester.Hide()
PictureBoxLondon.Hide()
txtFeaturesLiverpool.Hide()
txtFeaturesManchester.Hide()
txtFeaturesLondon.Hide()
End Sub
Private Sub cboxPod_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboxPod.SelectedIndexChanged
If cboxPod = Liverpool Then
lblLiverpoolPod.Show()
PictureBoxLiverpool.Show()
txtFeaturesLiverpool.Show()
End If
End Sub
Thank you for reading
Re: How do I use a combobox to make images and labels visible or hidden
You didn't explain what problems your having. But I'm in the mood for guessing so let me try to solve it without knowing what cbbox and Liverpool actually represent.
Code:
If cboxPod.Text = "Liverpool" Then
Re: How do I use a combobox to make images and labels visible or hidden
cboxPod is the ComoBox
Basically I want it so if I select the "Liverpool" item in the combobox, lblLiverpoolPod, PictureBoxLiverpool, and txtFeaturesLiverpool will show and vice versa for the "Manchester" item and the "London" item.
Re: [RESOLVED] How do I use a combobox to make images and labels visible or hidden
Because you have several controls that you're wanting to toggle the visibility on, I would suggest storing a Dictionary where the Key would represent the item in the ComboBox and the Value would represent a collection of the controls that should be visible.
Take a look at this example:
Code:
Public Class Form1
Private ReadOnly _visibilityControls As Dictionary(Of String, Control())
Sub New()
_visibilityControls = New Dictionary(Of String, Control()) From {
{"Liverpool", {lblLiverpoolPod, PictureBoxLiverpool, txtFeaturesLiverpool}},
{"Manchester", {lblManchesterPod, PictureBoxManchester, txtFeaturesManchester}},
{"London", {lblLondonPod, PictureBoxLondon, txtFeaturesLondon}}
}
End Sub
Private Sub cboxPod_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboxPod.SelectedIndexChanged
For Each pair In _visibilityControls
For Each futbolControl In pair.Value
futbolControl.Visible = (cboxPod.Text = pair.Key)
Next
Next
End Sub
End Class