Results 1 to 4 of 4

Thread: [RESOLVED] How do I use a combobox to make images and labels visible or hidden

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2021
    Posts
    29

    Resolved [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

    Name:  Screenshot_1.jpg
Views: 413
Size:  39.0 KB

    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.

    Name:  Screenshot_2.jpg
Views: 323
Size:  30.7 KB

    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

  2. #2
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,508

    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

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2021
    Posts
    29

    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.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    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
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width