Multiselect problem with listbox

  • Thread starter Thread starter kimiraikkonen
  • Start date Start date
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
 
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
 
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!
 
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.
 
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
 
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.
 
Back
Top