Solved

FileListBox or ListBox - Multiselect Problem

Posted on 2004-09-29
2
710 Views
Last Modified: 2013-12-26
One of the components of my GUI project is that I currently have a FileListBox that I need the user to be able to select multiple files from. I have the code in place to examine an array populated with the FileListBox contents and another array gets created of only the files that are selected. I have this functionality working fine, when the files are selected from top to bottom within the filelistbox contents, in other words in the same numerical order as the indexing. But If file selections are made in any other order, (bottom to top, or random) only the last file (or files selected, that coincide with indexing) get selected and thus get enumerated in the second array.

Is there a way to get the selected files from the FileListBox regardless of what order they are selected?

       
0
Comment
Question by:boris711
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 125 total points
ID: 12184148
How about this approach?

Option Explicit

' holds the names of the selected files
Private selectedFiles As Collection

Private Sub Form_Load()
    File1.Path = "c:\"
End Sub

' building the collection of selected files...
Private Sub Command1_Click()
    Dim i As Integer
   
    Set selectedFiles = New Collection
    For i = 0 To File1.ListCount - 1
        If File1.Selected(i) Then
            selectedFiles.Add File1.List(i)
        End If
    Next i  
End Sub

' enumerating the collection of selected files...
Private Sub Command2_Click()
    Dim curFile As Variant
   
    If Not (selectedFiles Is Nothing) Then
        For Each curFile In selectedFiles
            Debug.Print curFile
        Next
    End If
End Sub
0
 
LVL 1

Author Comment

by:boris711
ID: 12184586
That worked perfect!

I am relativly new to programming, and hadn't thought of using a collection vs. an array.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

775 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