tabing16
asked on
add/remove button between listboxes
Hi, i'm trying to move the item from listbox1 to listbox2 (i'm populating the item from database and put into the listbox1 anyway) by using add / remove buttons. When I click add button, the selected item will move to listbox 2 , as soon as I click remove, the item will go back to listbox1 from listbox2. The item must be gone in listbox1 as soon as i click add button and appear in listbox2 and vice versa.
this is my code :
Private Sub cmdadd_Click()
If lstSelect.ListIndex <> -1 Then
lstMove.AddItem lstSelect.List(lstSelect.L istIndex)
lstSelect.RemoveItem (lstSelect.ListIndex)
End If
End Sub
Private Sub cmdrenove_Click()
If lstMove.ListCount > 0 Then
If lstMove.ListIndex <> -1 Then
lstMove.RemoveItem lstMove.ListIndex
lstSelect.AddItem lstMove.ListIndex
End If
End If
End Sub
can anyone tell me what's wrong with this code ?? I think the add button works well, but the remove button doesn't . Can anyone help me ?
this is my code :
Private Sub cmdadd_Click()
If lstSelect.ListIndex <> -1 Then
lstMove.AddItem lstSelect.List(lstSelect.L
lstSelect.RemoveItem (lstSelect.ListIndex)
End If
End Sub
Private Sub cmdrenove_Click()
If lstMove.ListCount > 0 Then
If lstMove.ListIndex <> -1 Then
lstMove.RemoveItem lstMove.ListIndex
lstSelect.AddItem lstMove.ListIndex
End If
End If
End Sub
can anyone tell me what's wrong with this code ?? I think the add button works well, but the remove button doesn't . Can anyone help me ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The others code looks right, but they didn't explain it. You have to add the item to one list box BEFORE removing it from the other -- or it's lost.
ASKER
thx for the lovely code, you deserve the points
well seen & nice explanation, bob_online!
If lstMove.ListCount > 0 Then
If lstMove.ListIndex <> -1 Then
'!!!!!!!!!!!!
lstSelect.AddItem lstMove.ListIndex
lstMove.RemoveItem lstMove.ListIndex
'!!!!!!!!!!!!
End If
End If
End Sub