Populate Combobox based on a listbox selection

tjbarr

New member
Joined
Nov 19, 2008
Messages
3
Programming Experience
3-5
Very new to vb and this is just a static example - no database.

I have a list box and based on the choice of the listbox I want to populate a combobox:

VB.NET:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        lstSubject.Items.Add("Introduction to Computers")
        lstSubject.Items.Add("Beginning Programming")
        lstSubject.Items.Add("Intermediate Programming")
        lstSubject.Items.Add("System Analysis")
    End Sub


    Private Sub cboBooks_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboBooks.SelectedIndexChanged
        Dim strSelectedSubject As String
        strSelectedSubject = " "
        Select Case strSelectedSubject
            Case "Introduction to Computers"
                

            Case "Beginning Programming"

            Case "Intermediate Programming"

            Case "Intermediate Programming"

            Case "System Analysis"


        End Select
    End Sub
 
It looks like you're saying you want to populate a combobox based on the listbox selection but then you've got an event handler for selection change on a combo box.

Can you please clear up the confusion on what you're trying to do so we can give you useful help?
 
Figured it out

VB.NET:
Private Sub lstSubject_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstSubject.SelectedIndexChanged

        Dim strSubject As String
        strSubject = ""

        strSubject = CStr(lstSubject.SelectedItem)
        Select Case strSubject

            Case "Introduction to Computers"
                cboBooks.Items.Clear()
                cboBooks.Items.Add(conOFFICE2007)

            Case "Beginning Programming"
                cboBooks.Items.Clear()
                cboBooks.Items.Add(conVB2008)
                cboBooks.Items.Add(conVBNET)


            Case "Intermediate Programming"
                cboBooks.Items.Clear()
                cboBooks.Items.Add(conADVVB2005)


            Case "Systems Analysis"
                cboBooks.Items.Clear()
                cboBooks.Items.Add(conOOSOFTENG)
                cboBooks.Items.Add(conOOMODELING)

        End Select
    End Sub
 

Latest posts

Back
Top