I have created a Combo box with the 3 items.
And one more Combo Box with the 9 items.
When one item of 1st combo box selected,the 2nd combo box should show only 3 items out of 9 items.
how to do this?
I tried but not getting it.

Recommended Answers

What are the items in each and how are the items in combo2 supposed to be restricted after combo1 is selected?

Jump to Post

here is in example :

  1. in ComboBox1 Properties i put this item :
    "Superhero"
    "Badguy"

  2. in ComboBox1 SelectedIndexChanged event, i put this code :

        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If Me.ComboBox1.Text = "Superhero" Then
            With Me.ComboBox2
                .Items.Clear()
                .Items.Add("Batman")
                .Items.Add("Optimus") …
Jump to Post

All 5 Replies

What are the items in each and how are the items in combo2 supposed to be restricted after combo1 is selected?

here is in example :

  1. in ComboBox1 Properties i put this item :
    "Superhero"
    "Badguy"

  2. in ComboBox1 SelectedIndexChanged event, i put this code :

        Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If Me.ComboBox1.Text = "Superhero" Then
            With Me.ComboBox2
                .Items.Clear()
                .Items.Add("Batman")
                .Items.Add("Optimus")
                .Items.Add("Superman")
            End With
        ElseIf Me.ComboBox1.Text = "Badguy" Then
            With Me.ComboBox2
                .Items.Clear()
                .Items.Add("Lex Luthor")
                .Items.Add("Megathron")
                .Items.Add("Joker")
            End With
        End If
    End Sub
    

Beats me. I tried your example (except that I factored out ".Items" to give)

With ComboBox2.Items
    .Clear()
    .Add("Batman")

etc. and it works, Sorry I took so long to respond. We got to the the cottage last weekend and I didn't get my internet hooked up until this morning.

When you say you put "Superhero" and "Bad Guy" in properties, you do mean into the Items collection, correct?

yes sir :D, you are absolutely right.

Then I'm sorry I can't help. It works here for me.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.