Page 2 of 2

Re: Settings

Posted: Sun May 02, 2010 4:44 pm
by mandai
This will save the listview items to file when it closes, and it will load them when it next runs:
Code: Select all
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim lines As String() = File.ReadAllLines("items.txt")
        For i As Integer = 0 To lines.Count - 1
            ListBox1.Items.Add(lines(i))
        Next
End Sub

Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
        File.Delete("items.txt")
        For i As Integer = 0 To ListBox1.Items.Count - 1
            File.AppendAllText("items.txt", ListBox1.Items(i) & vbCrLf)
        Next
End Sub