By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,865 Members | 1,365 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,865 IT Pros & Developers. It's quick & easy.

Multiselect problem with listbox

P: n/a
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(open fileplaylist.FileName))

Else

Sep 26 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
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" wrote:
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(open fileplaylist.FileName))

Else

Sep 26 '07 #2

P: n/a
On Sep 27, 1:56 am, Kerry Moorman
<KerryMoor...@discussions.microsoft.comwrote:
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" wrote:
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(open fileplaylist.FileName))
Else- Hide quoted text -

- Show quoted text -
Mr. Moorman,
Very thanks. It worked!

Sep 27 '07 #3

P: n/a
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.

Sep 27 '07 #4

P: n/a
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" wrote:
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.

Sep 27 '07 #5

P: n/a
On Sep 28, 1:22 am, Kerry Moorman
<KerryMoor...@discussions.microsoft.comwrote:
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" wrote:
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.- Hide quoted text -

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

Thanks.

Sep 28 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.