title: How to transfer info from textboxes into a listbox in another form
body: <p>In this student registry of mine, I have a list box in the main form and in my second form I have add student. In this second form, I add a name to the name text box and numbers for the student which need to be separated by pipe characters ("|"). After the name and numbers in the textboxes are filled out when the user presses the okay button it should look like the hard coded students below. Code below </p>
  
  <p>First Form</p>
  
  <pre><code>private void listForm1_SelectedIndexChanged(object sender, EventArgs e)
          {
  
  
              string val = listForm1.GetItemText(listForm1.SelectedItem);
  
  
  
              string[] valArray = val.Split('|');
  
              int sum = 0;
              int scores = 0;
  
  
              for (int i = 1; i &lt; valArray.Length; i++)
              {
                  int num = Convert.ToInt32(valArray[i]);
                  sum += num;
                  scores++;
              }
  
  
              int average = sum / scores;
  
  
              txtAverage.Text = average.ToString();
              txtTotal.Text = sum.ToString();
              txtScoreCount.Text = scores.ToString();
          }
  
  
          private void Form1_Load(object sender, EventArgs e)
  
          {
  
              listForm1.Items.Add("Hamish Overtone" + "|" + 39 + "|" + 12 + "|" + 85);
              listForm1.Items.Add("Claudia Dye" + "|" + 44 + "|" + 56 + "|" + 85);
              listForm1.Items.Add("Mike Layne" + "|" + 12 + "|" + 47+ "|" + 28);
  
          }
  </code></pre>
  
  <p>Second Form</p>
  
  <pre><code> private void btnADDSCORE_Click(object sender, EventArgs e)
          {
  
  
              string userInput = txtNewScore.Text;
  
              txtNewScores.Text = txtNewScores.Text + " " + userInput;
  
              txtNewScore.Text = String.Empty;
  
  
          }
             private void btnNewOk_Click(object sender, EventArgs e)
          {
  
          }
  
          private void txtNewName_TextChanged(object sender, EventArgs e)
          {
  
          }
      }
  ERRORING PART:
  </code></pre>
  
  <p>private void listForm1_SelectedIndexChanged(object sender, EventArgs e)
      {</p>
  
  <pre><code>    // Get the value from the selected item
      string val = listForm1.GetItemText(listForm1.SelectedItem);
  
  
      // Split the item's value to a string array according to the pipe char
      string[] valArray = val.Split('|');
  
      int sum = 0;
      int scores = 0;
  
      // Iterate through all possible values and sum it up, 
      // while keeping count to how many numbers there are:
      for (int i = 1; i &lt; valArray.Length; i++)
      {
          int num = Convert.ToInt32(valArray[i]);
          sum += num;
          scores++;
      }
  
      // Calculate the  average. 
      // Keep in mind using an integer will create a whole number, without decimal points.        
      int average = sum / scores;
  
      // Place the average and the sum in textboxes
      txtAverage.Text = average.ToString();
      txtTotal.Text = sum.ToString();
      txtScoreCount.Text = scores.ToString();
  }
  </code></pre>