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

How are you reading data from text file ?

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
            Clean_ArrayList()
        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.Add(MyFile.ReadLine())
            'MyData(arrayIndex) = MyFile.ReadLine()
            'arrayIndex = arrayIndex + 1
        Loop

        MyFile.Close()

    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)

        Me.Controls.Add(ListView1)

       

        Do While Taskshowdetails.MyData.Count > 0

            Taskshowdetails.Read_File()

            Taskshowdetails.Read_Record_from_Array(MyRecord, rec_index)

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

        Loop

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

is the file delimited with a comma?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.