Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

filelistbox and multiselect

Status
Not open for further replies.

Lavey

IS-IT--Management
Jun 1, 2001
115
DE
hi guys.. I'm having a problem retrieving the selected values of files from a multiselect filelstbox. What i want to do is select multiple files and on a buton click push the filenames into a list box...

I can only seem to output the file that holds the focus within the filelistbox itself... and not any of the other selected files.

I checked msdn and got the following:
If the MultiSelect property is set to 0, you can use the ListIndex property to get the index of the selected item. However, in a multiple selection, the ListIndex property returns the index of the item contained within the focus rectangle, whether or not the item is actually selected.

Is there an alternative to this ?
Thx in advance...
LaVey
____________________________________
Eat [pc3], Sleep [pc3], Live [pc3]
 
you have to manually go from 0 to the .ListCount -1 and check the
file1.Selected(Index) to see if it TRUE. If it is then grab the .FileName from it.
 
This is how I extract multiple file names from CommonDialog file list:-

Dim i As Long
Dim n As Long
Dim L As Long
CommonDialog1.CancelError = True

List1.Clear

CommonDialog1.MaxFileSize = 2080 'default is 260 but limits selected files to approx 14 file names
CommonDialog1.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer
CommonDialog1.Filter = "*.avi; *.mpg; *.mpeg; *.mpe|*.avi;*.mpg;*.mpeg;*.mpe|" _
& "avi files (*.avi)|*.avi|m-peg Files (*.mpg)|*.mpg;*.mpeg;*.mpe|"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen

For n = 1 To Len(CommonDialog1.filename)
i = InStr(CommonDialog1.filename, Chr(0))
If i Then
If InStr(CommonDialog1.filename, "\") = 0 Then
List1.AddItem Left(CommonDialog1.filename, i)
End If
L = Len(CommonDialog1.filename)
CommonDialog1.filename = Right(CommonDialog1.filename, L - i)
End If
Next n

'list last entry in file name string, checking and removing folder if found
For n = Len(CommonDialog1.filename) To 1 Step -1
If Mid(CommonDialog1.filename, n, 1) = "\" Then
L = Len(CommonDialog1.filename)
CommonDialog1.filename = Right(CommonDialog1.filename, L - n)
Exit For
End If
Next n
List1.AddItem CommonDialog1.filename

Hope this helps
 
Here is the explanation of SemperFiDownUnda's method.
[tt]
Dim N As Long
For N = 0 To File1.ListCount - 1
If File1.Selected(N) Then
List1.AddItem File1.List(N)
End If
Next
[/tt]
 
nice1.. cheerz Hypetia & SemperFiDownUnda ... thats wot i was after..

/me pretty new to vb frmo vba background, was trying to use
List1.AddItem File1.selected(N)
____________________________________
Eat [pc3], Sleep [pc3], Live [pc3]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top