Read a text file and then add all lines to list box in VB.NET

后端 未结 3 832
不知归路
不知归路 2021-01-17 01:05

I have a text file in my desktop...

In this file we have five lines:

Line 1
Line 2
Line 3
Line 4
Line 5

If the user choose this tex

3条回答
  •  感动是毒
    2021-01-17 01:33

    Private Sub OpenList()
        Dim openfile = New OpenFileDialog()
        openfile.Filter = "Text (*.txt)|*.txt"
        If (openfile.ShowDialog() = System.Windows.Forms.DialogResult.OK) Then
            Dim myfile As String = openfile.FileName
            Dim allLines As String() = File.ReadAllLines(myfile)
            For Each line As String In allLines
                listBox.Items.Add(line)
            Next
        End If
    End Sub
    

提交回复
热议问题