Load LV

Posts 1–8 of 8 · Page 1 of 1
Load LV
This code saves the content of a lsitview. . .
But How I make to Load the items , subitems of each line?
Code:
My.Settings.Lista = TextBox1.Text
        My.Settings.Save()
        Try
            Dim write As New System.IO.StreamWriter(TextBox1.Text)
            For Each myItem As ListViewItem In ListView1.Items
                write.WriteLine(myItem.Text & " " & myItem.SubItems(1).Text) '// write Item and SubItem.
            Next
            write.Close()
        Catch
            MsgBox("Error")
        End Try
Do the same thing, but backwards
somthing like...

Code:
     try
       Dim File As StreamReader = File.OpenText("file.txt")
        Do While File.Peek <> -1
            listbox1.Items.Add(File.ReadLine())
        Loop
      Catch
             msgbox("Error")
      End try
        SuburbFile.Close()
?
Idk how..

" ListView1.Items.Add(read.ReadLine)" Just get all the line in the first items colum
Don't use " " as the delimiter for saving, what happens if an item has a space in it's text ? then your whole file will be useless.

Use a random symbol like "Æ" or something like that. To retrieve:

[highlight=vb.net]
Private Sub Retrieve(ByVal lv As ListView, ByVal file As String)
Dim lines As String() = IO.File.ReadAllLines(file).Where(Function(l As String) l.Length > 0).ToArray()
For Each line As String In lines
Dim sections As String() = line.Split("Æ")
Dim lvItem As New ListViewItem(sections(0))
If (sections.Length > 1) Then lvItem.SubItems.AddRange((From s As String In sections.Skip(1) Select New ListViewItem.ListViewSubItem(lvItem, s)).ToArray())
lv.Items.Add(lvItem)
Next
End Sub
[/highlight]

Untested though, just made it up :/
also why On my LV appears a message "Default " In black?
Screenshot? Otherwise idk wtfux you're talking about
Posts 1–8 of 8 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us