Hi,
i wanted to link options selected from Comb box A (general) to specific options in combo box B (specific). I want to pick a word in Combo box A that has specific words/phrases in Combo Box B show. But not all the words to show in the combo box B if they aren't associated with the Word picked in Combo Box A. Ex.When "Soda" is picked in A, only "Coke, Sprite, Fanta" should be visible in combo box b, not everything else.

This is the code i used to make the boxes, but i don't know how to link them.

Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' fills the combo boxes with values

Me.xGeneralComboBox.Items.Add("Soda")
Me.xGeneralComboBox.Items.Add("Juice")

Me.xxSpecificComboBox.Items.Add("Coke")
Me.xxSpecificComboBox.Items.Add("Sprite")
Me.xxSpecificComboBox.Items.Add("Fanta")

Me.xxSpecificComboBox.Items.Add("Apple")
Me.xxSpecificComboBox.Items.Add("Grape")
Me.xxSpecificComboBox.Items.Add("Pear")

Recommended Answers

All 8 Replies

Couldn't you use:

Pseudocode:

if generalcomobobox is soda then
comboboxspecific items = sprite, etc.
elseif generalcombobox is Juice then
comboboxspecific items = apple, etc.


you could do this in generalcombo box's SelectedIndexChangedEvent.

Hope this helps. Not sure if this is what you need or not. Sorry if off base.

It really didn't do anything..thanks anyways

What did you try? I didnt give any exact code as im sure you know. Show us some code. If i can't help, i'm sure another will.

so far i tried this and i got it to show "coke" in SpecificComboBox when i selected "soda" in GeneralComboBox...

Private Sub xGeneralComboBox_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles xGeneralComboBox.SelectedIndexChanged

If xGeneralComboBox.Text = "Soda" Then
xSpecificComboBox.Text = "Coke"

End If

However, it i want the dropdown list to also show the other soda specific items only, not just one..if i add more stuff like
xSpecificComboBox.Text = "Sprite"
xSpecificComboBox.Text = "Fanta"

to continue the code below the "coke" but above the "end if" the sprite and fanta don't show.

I've done so many statements, with different combinations now every sees to look the same....

I just create something in like 5 mins. This works for me. At form load i set enabled property of specific combo to false.

In the SelectedIndexChanged event for general combo box i enable the specific box and add the items based on the selected index. this is very basic and could be changed around if you needed it to be more sophisticated, but i was giving you a basic idea of how you could do what you were wanting.

Private Sub cmbGeneral_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbGeneral.SelectedIndexChanged

        cmbSpecific.Enabled = True
        cmbSpecific.Items.Clear()

        If cmbGeneral.SelectedIndex = 0 Then
            cmbSpecific.Items.Add("Sprite")
            cmbSpecific.Items.Add("Dr. Pepper")
        ElseIf cmbGeneral.SelectedIndex = 1 Then
            cmbSpecific.Items.Add("Apple Juice")
            cmbSpecific.Items.Add("Orange Juice")
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        cmbSpecific.Enabled = False

    End Sub
End Class

Ohhhhhhhhhhhhhhhhhhhhh I feel so dumb!!! I tried it and it worked...exactly what i was looking to do...i was stuck using this code:

If
Me.xGeneralComboBox.textselected =="Soda" then

Me.xSpecificComboBox.format("Sprite", "Fanta")

then i tried inheritance and i couldn't understand what i was doing...Thanks Alot!!!

I figured it out now, thanks everyone...

I used the Case Select method and i was able to add more things in A that B could Use (hopefully u get what am saying)

Awesome. Glad you got it figured out. Good luck.

Be a part of the DaniWeb community

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