[VB.NET]请问如何从OpenFileDialog中读取所有文件名到Listbox

前端之家收集整理的这篇文章主要介绍了[VB.NET]请问如何从OpenFileDialog中读取所有文件名到Listbox前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
请问如何从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? __________________________________________________________________________ 问题已经解决,不知是否正确? Private Sub Button3_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button3.Click On Error Resume Next Dim s As String With OpenFileDialog1 .Multiselect = True .FileName = .Filter = Excel文件(*.xls)|*.xls .FilterIndex = 1 End With OpenFileDialog1.ShowDialog() For Each s In OpenFileDialog1.FileNames ListBox1.Items.Add(s) Next End Sub __________________________________________________________________________ 那你用选取文件夹的方式好了。。。。 FolderBrowserDialog: If Me.FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then Me.ListBox1.DataSource = IO.Directory.GetFiles(Me.FolderBrowserDialog1.SelectedPath) End If __________________________________________________________________________ en 可以这么解决 __________________________________________________________________________ With OpenFileDialog1 .Multiselect = True .FileName = .Filter = Excel文件(*.xls)|*.xls .FilterIndex = 1 End With OpenFileDialog1.ShowDialog() ListBox1.Items.AddRange(OpenFileDialog1.FileNames) __________________________________________________________________________ 不必用循环而用ListBox.Items.AddRanage就可以加一个集合进来了,如上. __________________________________________________________________________ 高手啊! 佩服! __________________________________________________________________________ 感谢fangxinggood(JustACoder) 和平民百姓等高手! __________________________________________________________________________

猜你在找的VB相关文章