1.11M Members

how to hide some items in the listbox?

 
0
 

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!

 
0
 

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.
JR

 
0
 

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?

 
0
 

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

ListBox.Clear()

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

 
0
 

Its still hard,but thank you for helping!

Question Answered as of 3 Years Ago by JRitchie777
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article