WPF VB.NET:如何在列表框中插入记事本
我已经使用了下面的代码WPF VB.NET:如何在列表框中插入记事本,wpf,vb.net,listbox,Wpf,Vb.net,Listbox,我已经使用了下面的代码 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.
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中使用时,没有错误,但无法在列表框上显示记事本的内容。没有其他解决方案File.IO.ReadAllLines将返回字符串数组而不是集合。最好使用For循环
Foreach statement=您需要一个集合对象抱歉。。我必须向我的同事寻求解决办法。System.Windows.Forms.DialogResult上存在错误
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