Question : vb.net - save data from listview

hello there,
im using this old vb6 code to save data from a listview and its working like a charm but im trying to accomplish the same results in vb.net
how exactly can I do it?
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
Public Sub SaveData(mPath As String, LVW As ListView, useHeaders As Boolean)
    Dim FSO As FileSystemObject, TS As TextStream, i As Integer, j As Long, line As String
    Set FSO = New FileSystemObject
    Set TS = FSO.OpenTextFile(mPath, ForWriting, True)
 
    For j = 1 To LVW.ListItems.Count
        line = LVW.ListItems(j).Text & ":"
            For i = 1 To LVW.ListItems(j).ListSubItems.Count
                line = line & LVW.ListItems(j).ListSubItems(i).Text & ":"
            Next i
        TS.WriteLine Left(line, Len(line) - 1)
    Next j
 
    TS.Close
    Set TS = Nothing
    Set FSO = Nothing
End Sub

Answer : vb.net - save data from listview

Hmmm...sorry bout that.  I whipped that code up in the browser window a little too fast!  =\

Try this out:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
    Public Sub SaveData(ByVal mPath As String, ByVal LVW As ListView, ByVal useHeaders As Boolean)
        Dim line As String = ""
        Using sw As New System.IO.StreamWriter(mPath)
            If useHeaders Then
                line = ""
                For Each ch As ColumnHeader In LVW.Columns
                    line = line & ch.Text & ":"
                Next
                sw.WriteLine(line.TrimEnd(":"))
            End If
            For Each lvi As ListViewItem In LVW.Items
                line = ""
                For Each subLvi As ListViewItem.ListViewSubItem In lvi.SubItems
                    line = line & subLvi.Text & ":"
                Next
                sw.WriteLine(line.TrimEnd(":"))
            Next
        End Using
    End Sub
Random Solutions  
 
programming4us programming4us