two list boxes : move item from box on left to box on right??


Posted by graphage on April 26, 2001 12:56 PM

Hello...I have created two list boxes and a button to add the selected items on the left(listbox1) to the list box on the right (listbox2). I copied the code from a book which is pasted below. If I keep the Multi Select property at 'single' it works OK....but if I change the Multi Selct property to 'multi' then I get a type mismatch. How do I set this up so that my users can select multiple items (from listbox1) to be moved to the other listbox (listbox2)??? Thanks for the help!!

graphage

Private Sub AddButton_Click()
If ListBox1.ListIndex = -1 Then Exit Sub
If Not cbDuplicates Then **(this is a check box)**
For i = 0 To ListBox2.ListCount - 1
If ListBox1.Value = ListBox2.List(i) Then
Beep
Exit Sub
End If
Next i
End If
ListBox2.AddItem ListBox1.Value ***(this is where the mismatch is)***

End Sub



Posted by Dave Hawley on April 26, 2001 11:19 PM


Hi graphage

Try this:

Dim i As Integer
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) = True Then
ListBox2.AddItem (ListBox1.Selected(i))
End If
Next i


The ListBox Control does not have a Value property when the MultiSelect is set to True, hence your type mismatch error.


Dave


OzGrid Business Applications