title: Adding a variable to a listBox in VB.net Windows Form
body: <p>I am making a dvd database system in windows form and trying to display the dvd's entered by a user. Then display the Title, Director and Genre in 3 separate listBoxes. </p>
  
  <p>When the user enters the information through 3 separate text boxes, the information is stored in a structure I made called TDvd. This means I can call for example dvd.Title or dvd.Director. I also use the variable index to add this information to an array I made called Dvd(100) (just a random number I used to test).</p>
  
  <p>Here is the code I currently have for adding the items to the ListBox: </p>
  
  <pre><code>For i = 1 To noOfAddedDvds
      lstTitle.Items.Add(dvd(i).Title)
      lstDirector.Items.Add(dvd(i).Director)
      lstGenre.Items.Add(dvd(i).Genre)
  Next
  </code></pre>
  
  <p>The variable NoOfDvdsAdded is just a way of keeping track of the number of dvd's the user has already entered.</p>
  
  <p>I run this and enter the Title, Director and Genre, but when I try and display this information across the 3 listboxes, I get the error: </p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.ArgumentNullException' occurred in System.Windows.Forms.dll</p>
  </blockquote>
  
  <pre><code>Public Class Form1
  Structure TDvd
      Dim Title As String
      Dim Director As String
      Dim Genre As String
  End Structure
  Dim dvd(100) As TDvd
  Dim index As Integer = 0
  Dim noOfAddedDvds As Integer
  
  Private Sub btnAddToDatabase_Click(sender As Object, e As EventArgs) Handles btnAddToDatabase.Click
      If txtDirector.Text &lt;&gt; "" Or txtGenre.Text &lt;&gt; "" Or txtTitle.Text &lt;&gt; "" Then
          txtTitle.Text = dvd(index).Title
          txtDirector.Text = dvd(index).Director
          txtGenre.Text = dvd(index).Genre
          index += 1
          noOfAddedDvds += 1
      End If
      End Sub
  
  Private Sub btnDisplayDatabase_Click(sender As Object, e As EventArgs) Handles btnDisplayDatabase.Click
      Dim i As Integer
      For i = 0 To noOfAddedDvds
          MessageBox.Show(index &amp; ", " &amp; i)
          lstTitle.Items.Add(dvd(i).Title)
          lstDirector.Items.Add(dvd(i).Director)
          lstGenre.Items.Add(dvd(i).Genre)
          MessageBox.Show(index &amp; ", " &amp; i)
      Next
  
  End Sub
  </code></pre>
  
  <p>End Class</p>