Hi Everyone!

I have trouble in finding a way to hide or let certain amounts of items be unable to see in a listbox.

Here is what I have done so far

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Select Case ComboBox1.Text
            Case "Snacks"
                ListBox1.Items.Insert(0, "Nacho(Hot)")
                ListBox1.Items.Insert(1, "chips")
                ListBox1.Items.Insert(2, "hotdogs")

            Case "Drinks"
                ListBox1.Items.Insert(0, "Coke")
                ListBox1.Items.Insert(1, "Sprite")
                ListBox1.Items.Insert(2, "L&P")

        End Select
    End Sub

I want to be able to hide the items in listbox1 in the other case if the first case is selected
e.g if I choose snacks, items Nacho,chips and hotdogs only show up; if I choose Drinks then items coke,Sprite and L&P only show up.
Any suggestions?

Thank you!

6 Years
Discussion Span
Last Post by TrueVb.NetNoob

I don't think there is a .Visible property on listbox items. But for the ones you don't want you can easily execute a Items.Remove or Items.RemoveAt

A real way to do it would be to turn it into a data source, then you can create a query based on the top level item [Snacks] which would automatically filter the listbox to the correct items and automatically populate it.


Unfortunately I am just a beginner, and I don't know anything about database or any data source.

But the method u mentioned it to remove the item from the itembox, so does it mean I have to add to the listbox agian each time?


Yes you would, just like your are currently doing in your code.
Quicker way would be to


to clear out the whole contents and just add the values you want.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.