473,385 Members | 1,427 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,385 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 17349
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.