program-8

8. WAP to illustrate all functionalities of listbox and combobox.


listbox 



Option Explicit

Private Sub Form_Load()

    Dim intX    As Integer
    
    For intX = 1 To 100
        lstAvail.AddItem "Item # " & Format$(intX, "000")
    Next

End Sub


Private Sub cmdAdd_Click()

    Dim intListX            As Integer
    

    For intListX = lstAvail.ListCount - 1 To 0 Step -1

        If lstAvail.Selected(intListX) Then

            lstSelected.AddItem lstAvail.List(intListX)

            ' If you are using the optional ItemData property array,
            ' add the following line to carry the "ItemData baggage" along ...
            lstSelected.ItemData(lstSelected.NewIndex) = lstAvail.ItemData(intListX)

            lstAvail.RemoveItem intListX

        End If

    Next

End Sub

Private Sub cmdRemove_Click()

    Dim intListX            As Integer
    

    For intListX = lstSelected.ListCount - 1 To 0 Step -1

        If lstSelected.Selected(intListX) Then

            lstAvail.AddItem lstSelected.List(intListX)

            ' If you are using the optional ItemData property array,
            ' add the following line to carry the "ItemData baggage" along ...
            lstAvail.ItemData(lstAvail.NewIndex) = lstSelected.ItemData(intListX)

            lstSelected.RemoveItem intListX

        End If

    Next


End Sub









combobox

visual basic 6 combobox example


Private Sub btnAdd_Click()
    Dim I As Integer, Found As Integer

    Found = False
    For I = 0 To cboExample.ListCount - 1
        If cboExample.List(I) = cboExample.Text Then
            Found = True
        End If
    Next
    If Not Found Then
        cboExample.AddItem cboExample.Text
    End If
End Sub


Private Sub btnDelete_Click()
    For I = 0 To cboExample.ListCount - 1
        If cboExample.List(I) = cboExample.Text Then
            cboExample.RemoveItem I
            Exit For
        End If
    Next
End Sub

Private Sub btnExit_Click()
    End
End Sub

Private Sub Form_Load()
    cboExample.AddItem "Fruit"
    cboExample.AddItem "Vegetable"
    cboExample.AddItem "Meat"
    cboExample.AddItem "Soft drink"
    cboExample.AddItem "Water"
    cboExample.AddItem "Snacks"
End Sub