Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 42307

VS 2010 Reading Text File & Displaying In A Listview

$
0
0
Hi, I am having some trouble displaying text in a list view control. I have several columns in my list view,
and I am not sure how to read each line from a text file and 'place' it in the column.

Code:

Public Class Form1


    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        OpenFileDialog_ResourceFile.InitialDirectory = ("C:\users\name\documents\studentProjects")
    End Sub
    Private Sub Update_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click

        lisvProjects.BeginUpdate()
        Dim reader As New System.IO.StreamReader(OpenFileDialog_ResourceFile.FileName)
        Dim lines As String = reader.ReadToEnd
        For Each line As String In lines
            lisvProjects.Items.Add(line)
        Next
        reader.Close()

        ' Keep reading a line until we hit the end of the file
        Do While Not reader.EndOfStream
            ' Read a line and add to lisvProjects
            lisvProjects.Items.Add(reader.ReadLine())
        Loop

        reader.Close()





    End Sub


    Private Sub btnSelectFile_Click(sender As System.Object, e As System.EventArgs) Handles btnSelectFile.Click
        lisvProjects.Items.Clear()
        If OpenFileDialog_ResourceFile.ShowDialog() = DialogResult.OK Then
            txtProjectMainFile.Text = OpenFileDialog_ResourceFile.FileName
        Else
            Exit Sub
        End If
    End Sub
End Class

I know my code is a bit rough, but I am only a beginner. Thanks in advance! :)

Viewing all articles
Browse latest Browse all 42307

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>