Solved

add/remove button between listboxes

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

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 143

Expert Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Pull multiple cvs files into one access table 28 69
Problem to skip loop 6 64
Protecting vb6 & .Net code Obfuscation 18 151
Error with a code discussed on this page 5 31
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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.
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…
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…

839 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