title: VB how to write listbox items to a text file
body: <p>Okay so I'm creating a personal to-do list program inside of VB(Using visual studio) and I'm having trouble implementing the function where the items inside of the listbox get added to a textfile.</p>
  
  <p>Here is the code I have tried:</p>
  
  <p>Private Sub btnAddItem_Click(sender As Object, e As EventArgs) Handles btnAddItem.Click</p>
  
  <pre><code>    ''Adds item to the listbox.
      list.Items.Add(txtItem.Text)
  
      txtItem.Clear() ''Clears the textbox after adding item.
      txtItem.Select() ''Sets the cursor onto the textbox after adding item.
  
      Dim file As System.IO.StreamWriter
      file = My.Computer.FileSystem.OpenTextFileWriter("Test.txt", True)
      file.WriteLine(list.Items)
      file.Close()
  
  End Sub
  </code></pre>
  
  <p>I have also tried; file.WriteLine(list.Items.Text) however that is not an option inside of that statement. </p>
  
  <p>The button will not be how the list is saved but I'm just trying to get the test file to write properly first. The test file is created however if I type in:
  test 1
  test 2
  test 3 Into the listbox, the Test.txt file simply shows:</p>
  
  <pre><code>System.Windows.Forms.ListBox+ObjectCollection
  System.Windows.Forms.ListBox+ObjectCollection
  System.Windows.Forms.ListBox+ObjectCollection
  </code></pre>
  
  <p>Any help would be greatly appreciated! </p>