I am having a issue as above title. How to show data from file (txt file) in list view control?
Please help thanks

5 Years
Discussion Span
Last Post by aldeene

I read the file by using this code show at below. And now i need show the data in this txt file in listview.

Sub Read_File()
        'this is the solution for part 2 of the lab exercise
        Dim MyFile As New StreamReader("MyData.txt")

        'I will need to refresh my ArrayList = delete all the old data and read from the file again
        'otherwise all your data will be repeatatively appended
        If MyData.Count > 0 Then
        End If
        'The process of reading data stored in the file - line by line
        Do Until (MyFile.Peek = -1)
            'strTextData = strTextData & MyFile.ReadLine() & vbCrLf
            'MyData(arrayIndex) = MyFile.ReadLine()
            'arrayIndex = arrayIndex + 1


    End Sub

    Sub Read_Record_from_Array(ByRef rec_data As String(), ByVal rec_index As Integer)
        'Dim i As Integer

        Dim str_data As String

        str_data = MyData.Item(rec_index)
        ' Split string based on comma seprated values

        rec_data = str_data.Split(New Char() {","c})

    End Sub

You said, you want to get data into a listView, am I right?
So create columns (as many as you want, based on array number of data from the file), and use ListViewItem class to populate listView (use Text property for the 1st item, and Subitems.Add() method for the rest of th columns).

Will it go?


Dear Mitja

i am new in vb.net. can you show some code that can perform the result that are you talking about?


Now i have done the listview show but i face the issue of continue showing data from textfile cause my code make a result that showing 1 line of text data only. how i can solve it? help..

Private Sub TaskShow_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim a As String
        Dim MyRecord(4) As String
        rec_index = 0
        'Dim lv As New ListView()

        ListView1.View = View.Details

        ListView1.HeaderStyle = ColumnHeaderStyle.Clickable

        ListView1.Columns.Add("Title", 60, HorizontalAlignment.Center)

        ListView1.Columns.Add("Description", 60, HorizontalAlignment.Center)

        ListView1.Columns.Add("Date", 60, HorizontalAlignment.Center)

        ListView1.Columns.Add("Time", 60, HorizontalAlignment.Center)



        Do While Taskshowdetails.MyData.Count > 0


            Taskshowdetails.Read_Record_from_Array(MyRecord, rec_index)

            ListView1.Items.Add(New ListViewItem(MyRecord))


Does you text file contains data in multiple columns ? How you distinguish between columns in a text file ?

Edited by debasisdas: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.