Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

add/remove button between listboxes

Posted on 2002-05-03
5
Medium Priority
?
174 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 150 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 143

Expert Comment

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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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 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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

609 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