Alright, Here is my problem. I am using VB 2008. I am trying to get information from comboboxes to link to others. by that I am trying to get a flowlist going.
box1= vehicle year
box2= vehicle make..... then model, etc.
I appreciate any help that comes my way.
here is what I have for now:

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        Select Case ("SELECT YEAR")
            Case 1997
                ComboBox1.Items.Add("1997")
                ComboBox2.Items.Add("Nissan")
            Case 1998
                ComboBox1.Items.Add("1998")
                ComboBox2.Items.Add("Nissan")
            Case 1999
                ComboBox1.Items.Add("1999")
            Case 2000
                ComboBox1.Items.Add("2000")
            Case 2001
                ComboBox1.Items.Add("2001")
                ComboBox2.Items.Add("Scion")

        End Select

    End Sub


Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
       
        Select Case ("SELECT VEHICLE")

            Case 1999

                ComboBox2.Items.Add("Toyota")


            Case 1997
                ComboBox2.Items.Add("Toyota")
                ComboBox2.Items.Add("Nissan")
        End Select
        Me.ComboBox2.Items.AddRange(List2(Me.ComboBox1.SelectedIndex))

    End Sub

    Private Sub ComboBox3_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged

    End Sub

    Private Sub ComboBox4_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

    End Sub

Recommended Answers

All 7 Replies

So what's the problem you're having? It took me like 5 mins to do this, check out this code and see if it helps you:

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "1997" Then
            ComboBox2.Items.Add("Nissan")
        End If
        If ComboBox1.Text = "1998" Then
            ComboBox2.Items.Add("Ford")
        End If
        If ComboBox1.Text = "1999" Then
            ComboBox2.Items.Add("Honda")
        End If
        If ComboBox1.Text = "2000" Then
            ComboBox2.Items.Add("Toyota")
        End If
        If ComboBox1.Text = "2001" Then
            ComboBox2.Items.Add("Mitsubishi")
        End If
        If ComboBox1.Text = "2002" Then
            ComboBox2.Items.Add("Hyundai")
        End If
    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        If ComboBox2.Text = "Nissan" Then
            ComboBox3.Items.Add("Maxima")
            ComboBox3.Items.Add("Altima")
        End If
        If ComboBox2.Text = "Ford" Then
            ComboBox3.Items.Add("Escort")
            ComboBox3.Items.Add("Mustang")
        End If
        If ComboBox2.Text = "Honda" Then
            ComboBox3.Items.Add("Civic")
            ComboBox3.Items.Add("Accord")
        End If
        If ComboBox2.Text = "Toyota" Then
            ComboBox3.Items.Add("Camry")
            ComboBox3.Items.Add("Corolla")
        End If
        If ComboBox2.Text = "Mitsubishi" Then
            ComboBox3.Items.Add("Eclipse")
            ComboBox3.Items.Add("Lancer")
        End If
        If ComboBox2.Text = "Hyundai" Then
            ComboBox3.Items.Add("Accent")
            ComboBox3.Items.Add("Elantra")
        End If
    End Sub

Thank you, I will try this snippet as soon as I get off of work today. I will let you know how it goes. Thanks for the reply.

wow thank you so very much. I totally have never used the if statement in depth before, this is such a learning experience, thanks crazyhorse09.

Glad I could help, one thing I forgot to do is add clear, like in the following code, so that when you select two or more choices in the same combobox, it resets, otherwise you have the choices from both selections. Also, if you could mark this thread as solved that would be great, thanks.

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
        If ComboBox1.Text = "1997" Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("Nissan")
        End If
        If ComboBox1.Text = "1998" Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("Ford")
        End If
        If ComboBox1.Text = "1999" Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("Honda")
        End If
        If ComboBox1.Text = "2000" Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("Toyota")
        End If
        If ComboBox1.Text = "2001" Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("Mitsubishi")
        End If
        If ComboBox1.Text = "2002" Then
            ComboBox2.Items.Clear()
            ComboBox2.Items.Add("Hyundai")
        End If
    End Sub

    Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        If ComboBox2.Text = "Nissan" Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("Maxima")
            ComboBox3.Items.Add("Altima")

        End If
        If ComboBox2.Text = "Ford" Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("Escort")
            ComboBox3.Items.Add("Mustang")
        End If
        If ComboBox2.Text = "Honda" Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("Civic")
            ComboBox3.Items.Add("Accord")
        End If
        If ComboBox2.Text = "Toyota" Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("Camry")
            ComboBox3.Items.Add("Corolla")
        End If
        If ComboBox2.Text = "Mitsubishi" Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("Eclipse")
            ComboBox3.Items.Add("Lancer")
        End If
        If ComboBox2.Text = "Hyundai" Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("Accent")
            ComboBox3.Items.Add("Elantra")
        End If
    End Sub

again thanks for all of your help. also when the query in the combobox is cleared I have no options to chose from.

combobox1.items.clear()

is the option to clear correct or should it be

combobox1.text.remove()

thanks.

I have it setup so once you select an option, the NEXT combobox is cleared first, THEN the options are added.

If ComboBox2.Text = "Hyundai" Then
            ComboBox3.Items.Clear()
            ComboBox3.Items.Add("Accent")
            ComboBox3.Items.Add("Elantra")
        End If

When you select Hyundai from combobox2 in my example, it clears combobox3 first, to remove any previous options added, then adds accent and elantra as options to select from combobox3. Does that make sense? If not please be more specific about what you need.

Sorry. I found the error in my code. I had an option to open a new vehicle. when the option was selected it would clear the combo-boxes. here is the code.

Private Sub NewVehicleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewVehicleToolStripMenuItem.Click
        ComboBox1.ResetText()
        ComboBox2.ResetText()
        ComboBox3.ResetText()
        ComboBox4.ResetText()
        ComboBox1.Items.Clear()
        ComboBox2.Items.Clear()
        ComboBox3.Items.Clear()
        ComboBox4.Items.Clear()

    End Sub

What I did wrong was I cleared the text in box 1. When I removed the command to remove the text from box 1 it works. here is the code:

Private Sub NewVehicleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewVehicleToolStripMenuItem.Click

        ComboBox2.ResetText()
        ComboBox3.ResetText()
        ComboBox4.ResetText()
        ComboBox2.Items.Clear()
        ComboBox3.Items.Clear()
        ComboBox4.Items.Clear()

    End Sub
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.