KingJ
KingJ

Reputation: 123

How to Show specific item from combobox 1 when i choose certain items from another combobox 2

net and i need help.

In my coding i have 2 combobox so lets assume combobox1 and combobox2

In my combobox1 i have 3 items(1,2,3) In my combobox2 i have 5 items lets say(1,2,3,4,5)

How do i setup my combobox to show certain items.. let say if i choose 1 from combobox1 then it will show 2,3,4 and will hide 1,5 in combobox2, if i choose 2 from combobox1 then it will show 1,5 and it will hide 2,3,4 for example..

I tried combobox2.item.add but all it did is duplicating items when i choose another item from combobox1 and play it back and forth by choosing different items in combobox1

Example code Below:

Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
    If ComboBox3.SelectedItem.ToString() = "1" Then
        ComboBox4.Items.Add("2")
        ComboBox4.Items.Add("3")
        ComboBox4.Items.Add("4")
    ElseIf ComboBox3.SelectedItem.ToString() = "2" Then
        ComboBox4.Items.Add("1")
        ComboBox4.Items.Add("5")
    Else
        ComboBox4.Items.Add("6")
    End If

End Sub

Upvotes: 1

Views: 774

Answers (1)

Aousaf Rashid
Aousaf Rashid

Reputation: 5738

easy..

Private sub ComboBox1_indexchanged
 combo2.items.clear
 Dim ab() As String = New String() _      {"1", "2", "3"}
 if combo1.text="1" then
 combo2.items.addrange(ab)

Upvotes: 1

Related Questions