请问如何从OpenFileDialog中读取所有文件名到Listbox
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
On Error Resume Next
With OpenFileDialog1
.Multiselect = True
.FileName = " "
.Filter = "Excel文件(*.xls)|*.xls "
.FilterIndex = 1
End With
OpenFileDialog1.ShowDialog()
ListBox1.Items.Add(OpenFileDialog1.FileName)
End Sub
请问如何从OpenFileDialog中读取所有文件名到Listbox?
[解决办法]
那你用选取文件夹的方式好了。。。。
FolderBrowserDialog:
If Me.FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
Me.ListBox1.DataSource = IO.Directory.GetFiles(Me.FolderBrowserDialog1.SelectedPath)
End If
[解决办法]
With OpenFileDialog1
.Multiselect = True
.FileName = " "
.Filter = "Excel文件(*.xls)|*.xls "
.FilterIndex = 1
End With
OpenFileDialog1.ShowDialog()
ListBox1.Items.AddRange(OpenFileDialog1.FileNames)