Solved

add/remove button between listboxes

Posted on 2002-05-03
5
168 Views
Last Modified: 2012-05-04
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.ListIndex)
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 ?
0
Comment
Question by:tabing16
5 Comments
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 6988237
Private Sub cmdrenove_Click()
If lstMove.ListCount > 0 Then
   If lstMove.ListIndex <> -1 Then
'!!!!!!!!!!!!
       lstSelect.AddItem lstMove.ListIndex
       lstMove.RemoveItem lstMove.ListIndex
'!!!!!!!!!!!!
   End If
End If
End Sub

0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 50 total points
ID: 6988252
hhmmmm, minor correction:

Private Sub cmdrenove_Click()
  If lstMove.Listindex <>-1 Then
'!!!!!!!!!!!!
      lstSelect.AddItem lstMove.List(lstMove.ListIndex)
      lstMove.RemoveItem lstMove.ListIndex
'!!!!!!!!!!!!
  End If
End Sub

Cheers
0
 
LVL 5

Expert Comment

by:bob_online
ID: 6988387
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.
0
 

Author Comment

by:tabing16
ID: 6990990
thx for the lovely code, you deserve the points
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 6993676
well seen & nice explanation, bob_online!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now