我已经使用了以下代码。
Dim openfile1 = New Microsoft.Win32.OpenFileDialog With {.Filter = "Text (*.Text)|*.txt"}
If (openfile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then
For Each line As String In File.ReadAllLines(openfile1.FileName)
ListBox1.Items.Add(line)
Next
End If
此代码在Windows窗体上提供,当我在WPF中使用时没有错误但无法在列表框中显示记事本的内容。没有其他解决方案
答案 0 :(得分:0)
File.IO.ReadAllLines
将返回一个字符串数组,而不是collection
。您最好使用For
循环。
Dim openfile1 = New Microsoft.Win32.OpenFileDialog With {.Filter = "Text (*.Text)|*.txt"}
If (openfile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then
For i = 0 To Ubound(File.ReadAllLines(openfile1.FileName),1)
ListBox1.Items.Add(File.ReadAllLines(openfile1.FileName)(i))
Next
End If
Foreach
statement =您需要一个collection
对象