Concept : This code checks the whole list(List1) through a for loop and then add the selected items to the other List2
NOTE : Make sure that the multiselect property of listboxes is '1-Simple'
Private Sub CmdcopyToList2_Click() Dim i As Integer If List1.SelCount = 1 Then List2.AddItem List1.Text Else For i = List1.ListCount - 1 To 0 Step -1 If List1.Selected(i) = True Then List2.AddItem List1.List(i) End If Next i End If End Sub
Explanation : We are cheking selcount just for learning purposes(i.e, to learn the basic adding procedure).
If more then ONE items are selected, the loops checks each list item one by one and then adds the item if IT IS SELECTED.
NOTE : Step -1 is only for learning purpose, loop can be runned either way.
REMOVING
Private Sub CmdRemove_Click() For i = List1.ListCount - 1 To 0 Step -1 If List1.Selected(i) = True Then List1.RemoveItem (i) End If Next i End Sub
Explanation : Just as the previous one, this too Removes the selected Items.
I Hope this helped






MultiQuote




|