Solved

add/remove button between listboxes

Posted on 2002-05-03
5
166 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

708 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

17 Experts available now in Live!

Get 1:1 Help Now