473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Selecting Multiple Files

Hi there,

I'm just starting at VB.NET (all VB come to that), and have what's probably
a very basic question:

I have a form in Visual Studio 2003 that has a listbox that is meant to be
populated with file names from the OpenFileDialog method (see below). The
problem is that if you select, say three files in the Open File dialogue
box, the listbox is populated with three of the same file rather than three
different files.

Any clues on where I'm going wrong?

Many thanks

John

Private Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim openFileDialog1 As New OpenFileDialog

Dim fName As String

openFileDialog1.InitialDirectory = "c:\"

openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"

openFileDialog1.FilterIndex = 2

openFileDialog1.RestoreDirectory = True

openFileDialog1.Multiselect = True

If openFileDialog1.ShowDialog() = DialogResult.OK Then

For Each fName In openFileDialog1.FileNames

lstWrkFiles.Items.Add(openFileDialog1.FileName)

Next

End If

End Sub
Nov 21 '05 #1
4 17356
John,

In your For Each loop:

lstWrkFiles.Items.Add(fName)

Kerry Moorman

"John" wrote:
Hi there,

I'm just starting at VB.NET (all VB come to that), and have what's probably
a very basic question:

I have a form in Visual Studio 2003 that has a listbox that is meant to be
populated with file names from the OpenFileDialog method (see below). The
problem is that if you select, say three files in the Open File dialogue
box, the listbox is populated with three of the same file rather than three
different files.

Any clues on where I'm going wrong?

Many thanks

John

Private Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim openFileDialog1 As New OpenFileDialog

Dim fName As String

openFileDialog1.InitialDirectory = "c:\"

openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"

openFileDialog1.FilterIndex = 2

openFileDialog1.RestoreDirectory = True

openFileDialog1.Multiselect = True

If openFileDialog1.ShowDialog() = DialogResult.OK Then

For Each fName In openFileDialog1.FileNames

lstWrkFiles.Items.Add(openFileDialog1.FileName)

Next

End If

End Sub

Nov 21 '05 #2
That's great. Thanks very much Kerry.

Seems obvious now you point it out!

John
"Kerry Moorman" <Ke**********@discussions.microsoft.com> wrote in message
news:B9**********************************@microsof t.com...
John,

In your For Each loop:

lstWrkFiles.Items.Add(fName)

Kerry Moorman

"John" wrote:
Hi there,

I'm just starting at VB.NET (all VB come to that), and have what's
probably
a very basic question:

I have a form in Visual Studio 2003 that has a listbox that is meant to
be
populated with file names from the OpenFileDialog method (see below).
The
problem is that if you select, say three files in the Open File dialogue
box, the listbox is populated with three of the same file rather than
three
different files.

Any clues on where I'm going wrong?

Many thanks

John

Private Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim openFileDialog1 As New OpenFileDialog

Dim fName As String

openFileDialog1.InitialDirectory = "c:\"

openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"

openFileDialog1.FilterIndex = 2

openFileDialog1.RestoreDirectory = True

openFileDialog1.Multiselect = True

If openFileDialog1.ShowDialog() = DialogResult.OK Then

For Each fName In openFileDialog1.FileNames

lstWrkFiles.Items.Add(openFileDialog1.FileName)

Next

End If

End Sub

Nov 21 '05 #3
John,

In your For Each loop:

lstWrkFiles.Items.Add(fName)

Kerry Moorman

"John" wrote:
Hi there,

I'm just starting at VB.NET (all VB come to that), and have what's probably
a very basic question:

I have a form in Visual Studio 2003 that has a listbox that is meant to be
populated with file names from the OpenFileDialog method (see below). The
problem is that if you select, say three files in the Open File dialogue
box, the listbox is populated with three of the same file rather than three
different files.

Any clues on where I'm going wrong?

Many thanks

John

Private Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim openFileDialog1 As New OpenFileDialog

Dim fName As String

openFileDialog1.InitialDirectory = "c:\"

openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"

openFileDialog1.FilterIndex = 2

openFileDialog1.RestoreDirectory = True

openFileDialog1.Multiselect = True

If openFileDialog1.ShowDialog() = DialogResult.OK Then

For Each fName In openFileDialog1.FileNames

lstWrkFiles.Items.Add(openFileDialog1.FileName)

Next

End If

End Sub

Nov 21 '05 #4
That's great. Thanks very much Kerry.

Seems obvious now you point it out!

John
"Kerry Moorman" <Ke**********@discussions.microsoft.com> wrote in message
news:B9**********************************@microsof t.com...
John,

In your For Each loop:

lstWrkFiles.Items.Add(fName)

Kerry Moorman

"John" wrote:
Hi there,

I'm just starting at VB.NET (all VB come to that), and have what's
probably
a very basic question:

I have a form in Visual Studio 2003 that has a listbox that is meant to
be
populated with file names from the OpenFileDialog method (see below).
The
problem is that if you select, say three files in the Open File dialogue
box, the listbox is populated with three of the same file rather than
three
different files.

Any clues on where I'm going wrong?

Many thanks

John

Private Sub button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click

Dim openFileDialog1 As New OpenFileDialog

Dim fName As String

openFileDialog1.InitialDirectory = "c:\"

openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"

openFileDialog1.FilterIndex = 2

openFileDialog1.RestoreDirectory = True

openFileDialog1.Multiselect = True

If openFileDialog1.ShowDialog() = DialogResult.OK Then

For Each fName In openFileDialog1.FileNames

lstWrkFiles.Items.Add(openFileDialog1.FileName)

Next

End If

End Sub

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: james.dixon | last post by:
Hi I was wondering if anyone else had had this problem before (can't find anything on the web about it). I have three select elements (list boxes - from here on I'll refer to them as 'the...
4
by: Chris Jones | last post by:
Does anyone know of a C#/ASP.NET Open File dialog that I can use in an aspx page that allows multiselect? I need to be able to select and upload numerous files. Is there a reason why MS has made...
1
by: Olaf Baeyens | last post by:
In .NET v1.1 I am trying to select multiple files using OpenFileDialog like this OpenFileDialog openFileDialog=new OpenFileDialog(); openFileDialog.Multiselect=true; i...
1
by: Jay | last post by:
Hi All, My users are complaining about the page refreshing when they are selecting multiple rows in a datagrid. Has anyone tried to manage this using javascript? I tried smartnavigation but that...
1
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
1
by: Bob Loveshade | last post by:
I am looking for an example that shows how to select and highlight multiple rows in a DataGrid. My DataGrid is part of a Web User Control which is contained in an ASPX page. I haven't been...
0
by: John | last post by:
Hi there, I'm just starting at VB.NET (all VB come to that), and have what's probably a very basic question: I have a form in Visual Studio 2003 that has a listbox that is meant to be...
2
by: areef.islam | last post by:
Hi, I am kinda new to javascript and I am having this problem with selecting multiple options from a select tag. Hope someone can help me out here. here is my code...
2
by: junaid | last post by:
Hi, please help me i want to select multiple files including directories using OpenFileDialog, but i cant get directory name(s) in FileNames property i am using J#, VS2005 are there any method...
0
TjFL
by: TjFL | last post by:
I have a form where specific external files are selected by the user depending on needs. Each item listed on the form has 4 Yes/No boxes next to it where they select what they want. The result will...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.