Multiselect problem with listbox

K

kimiraikkonen

Hello,
I have openfiledialog control named "openfileplaylist" and multi-
selectpropert is TRUE. But although i select more than one files using
"shift+arrows", i only get one file listed in my listbox.

What's wrong?

Code:

If openfileplaylist.ShowDialog() = Windows.Forms.DialogResult.OK Then

ListBox1.Items.Add(System.IO.Path.GetFileName(openfileplaylist.FileName))

Else
 
G

Guest

kimiraikkonen,

Did you look in the online help for the openfiledialog's MultiSelect
property? The online help clearly explains that the selected filenames are
returned in the openfiledialog's FileNames property.

The FileNames property is an array of strings. Each element of the array is
one of the selected filenames.

One option would be to loop through the FileNames array, adding each
filename to the listbox:

For Each f As String In openfileplaylist.FileNames
ListBox1.Items.Add(System.IO.Path.GetFileName(f))
Next

Kerry Moorman
 
K

kimiraikkonen

kimiraikkonen,

Did you look in the online help for the openfiledialog's MultiSelect
property? The online help clearly explains that the selected filenames are
returned in the openfiledialog's FileNames property.

The FileNames property is an array of strings. Each element of the array is
one of the selected filenames.

One option would be to loop through the FileNames array, adding each
filename to the listbox:

For Each f As String In openfileplaylist.FileNames
ListBox1.Items.Add(System.IO.Path.GetFileName(f))
Next

Kerry Moorman






- Show quoted text -

Mr. Moorman,
Very thanks. It worked!
 
K

kimiraikkonen

But also i want to ask this, how could be the code that inserts the
"full path" of each files (multi-selection) into listbox1 instead of
only filenames?

Thanks.
 
G

Guest

kimiraikkonen,

I think the FileNames array contains the full path, so in that case you
would not want to use the GetFileName method:

For Each f As String In openfileplaylist.FileNames
ListBox1.Items.Add(f)
Next

Kerry Moorman
 
K

kimiraikkonen

kimiraikkonen,

I think the FileNames array contains the full path, so in that case you
would not want to use the GetFileName method:

For Each f As String In openfileplaylist.FileNames
ListBox1.Items.Add(f)
Next

Kerry Moorman






- Show quoted text -

Mr. Moorman,
You "really" helped. Thanks for the advice. Here's my second 5-star
rating for you.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top