I'm having trouble displaying multiple file names with OpenFileDialog class. I have already selected Multiselect set to true, and can select more than one file in the DialogBox, but only 1 file is printed in the TextBox1 area.
Here is my code:
Public Class Form2
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
OpenFileDialog1.ShowDialog()
End Sub
Private Sub OpenFileDialog1_FileOk(sender As Object, e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
' Dialog Result
Dim FilesSelected As DialogResult
' Are Files Selected?
If (FilesSelected = System.Windows.Forms.DialogResult.OK) Then
' If Files Identify Array
Dim file() As String
file = OpenFileDialog1.FileNames
For Each file In OpenFileDialog1.FileNames
TextBox1.Text = (CurDir() & "")
Next
End If
End Sub
End Class
First, be sure to have the MultiLine property for the TextBox set to true and resize it to have an acceptable height. Also set the ScrollBars property to Vertical
Then your code could be written in this way (without an explicit loop)
Dim txt = string.Join(Environment.NewLine, OpenFileDialog1.FileNames)
TextBox1.Text = txt