Hey all, I'm trying to do something and read text from page to listview in columns, problem is i get first row, but second third etc it dont insert idk why, im talking about ROWs here is my code check it out and let me know what is wrong?

 Try
            Dim strTemp() As String
            Dim LVItem As New ListViewItem
            strTemp = eResult.Split("!"c)
             LVItem.Text = strTemp(0).ToString
            ListView1.Items.Add(LVItem)
           LVItem.SubItems.Add(strTemp(1).ToString)
            If strTemp.Length > 2 Then LVItem.SubItems.Add(strTemp(2).ToString)
            If strTemp.Length > 3 Then LVItem.SubItems.Add(strTemp(3).ToString)
            If strTemp.Length > 4 Then LVItem.SubItems.Add(strTemp(4).ToString)
        Catch ex As Exception
            MessageBox.Show("Error reading file." & ex.Message)
        End Try

Please post your input data. Also, why are you using the ToString method on data that is already a string? Is it your intention to only add strings of a certain minimum length or is there some other reason you are checking for length >2, >3, etc. The code you posted only adds one row because as far as I can tell it only runs once unless it is inside a loop which you are not showing.

Hi, it's like Reverend Jim says. If you are getting your data from a textfile you could do it like this

Dim strTemp As String = My.Computer.FileSystem.ReadAllText("C:\TempText.txt") 'where ever you get your text from
        Dim lines() As String = Split(strTemp, vbCrLf)
        For Each line In lines
            For i = 0 To 4 'is 5 columns
                Dim LVItem As New ListViewItem(line.Split("!"c))
                ListView1.Items.Add(LVItem)
            Next
        Next

BTW, it's easier to read the file by

Dim lines() As String = System.IO.File.ReadAllLines(myfile)

and if you can guarantee that your input lines are properly formatted you can add them all by

For Each line As String In System.IO.File.ReadAllLines(myfile)
    ListView1.Items.Add(New ListViewItem(line.Split("!")))
Next
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.