Monday, December 10, 2012

List Box and Combo Box control in visual basic


Dim str As String
Dim c As Integer
Private Sub CmdADD_Click()
str = InputBox("enter color Name:")
CmbColor.AddItem str
End Sub
Private Sub CmdRemove_Click()
If CmbColor.ListIndex >= 0 Then
CmbColor.RemoveItem CmbColor.ListIndex
MsgBox "selected item is removed"
Else
MsgBox "plz select an item"
End If
End Sub
Private Sub CmdItem_Click()
If CmbColor.ListIndex >= 0 Then
MsgBox "selected item is: " & CmbColor.List(CmbColor.ListIndex)
Else
MsgBox "plz select an item"
End If
End Sub
Private Sub CmdCount_Click()
c = CmbColor.ListCount
MsgBox "total no. of items are: " & c
End Sub
Private Sub CmdLstindx_Click()
If CmbColor.ListIndex >= 0 Then
MsgBox "Index of selected item is: " & CmbColor.ListIndex
Else
MsgBox "plz select an item"
End If
End Sub
Private Sub CmdClear_Click()
CmbColor.Clear
End Sub

Private Sub CmdAddcart_Click()
Dim check As Integer
If CmbColor.ListIndex >= 0 Then
For i = 0 To lstcolor.ListCount Step 1
If (CmbColor.List(CmbColor.ListIndex) = lstcolor.List(i)) Then
check = 1
End If
Next
If check = 1 Then
MsgBox ("Selected Color Already Exist")
Else
lstcolor.AddItem CmbColor.List(CmbColor.ListIndex)
End If
Else
MsgBox "plz select an item"
End If
End Sub
Private Sub CmdAddAll_Click()
lstcolor.Clear
For i = 0 To CmbColor.ListCount Step 1
lstcolor.AddItem CmbColor.List(i)
Next
End Sub
Private Sub Cmdrmvcart_Click()
lstcolor.RemoveItem lstcolor.ListIndex
End Sub
Private Sub CmdRmvAll_Click()
lstcolor.Clear
End Sub
Private Sub CmdEXIT_Click()
End
End Sub



 Output

Note:- Please set some property of your control like caption or id corresponding to your control