J
John
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
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