Moving items between listbox

simon03

Registered User.
Local time
Today, 06:43
Joined
Aug 13, 2014
Messages
40
Hello,

I have two listbox (SearchResults5 has two columns) and list_asset_add (one column) both have Extended multi-selection active. I have this code that automatically moves the items between the two listbox (it runs after pushing a button):

Code:
Sub CopiTo_Click()

Dim Msg As String
Dim i As Variant

If SearchResults5.ListIndex = -1 Then
    Msg = "Nothing"

Else

    For Each i In SearchResults5.ItemsSelected
        Msg = "" & SearchResults5.Column(1, i)
        list_asset_add.AddItem (Msg)
    Next i
End If


End Sub

This works quite well if I manually select the items that I want to move. Most of the times SearchResults5 has lots of elements so I have decided to create a "Select All" button to speed up the process, here the code:

Code:
Private Sub Command271_Click()
Dim n As Integer
With Me.SearchResults5
    For n = 0 To .ListCount - 1
        .Selected(n) = True
    Next n
End With
End Sub

When I use the "Select All" button and I try to move the items between the two listbox, the function does NOT work.

BUT if I manually select one or more items in the first listbox, then I clear the selection and finally I use the subroutine to move the items between the two listbox, then the it works well again.

Any idea how to make it work properly?

Thanks :)
 
Thanks for your answer but that video does not solve my issue. The proposed implementation of that video implies that each element, that I want to move, is manually selected. That functionality already works in my implementation.

What does not work is to move items that have been selected with another subroutine instead of manually.
 
Use the ItemsSelected.Count instead of ListIndex:
Code:
If SearchResults5.ItemsSelected.Count = 0 Then
    Msg = "Nothing"
 

Users who are viewing this thread

Back
Top Bottom