title: C# Passing Values between Forms into DataGridView
body: <p>I have 3 forms, say Form1 (with datagridview1 and datagridview2), Form2 and Form3. In Form1 I want to open Form2, edit text boxes and when a button is clicked it should pass the values to Form1, which would add it to datagridview1. The same will happen with Form3 after text is entered and passed to Form1 and added to datagridview2. When I click to open Form2, edit the data and pass it through, it adds the values to the datagrid, no problem, but when I click to open Form3 and do the second datagrid, it erases the data in datagridview1. How do I get Form1 to keep the previous datagrid's values and not erase it. At the moment I have this going:</p>
  
  <p>In Form1:</p>
  
  <pre><code>    public string value1
      {
          set { this.dataGridView1.Rows[0].Cells[0].Value = value; }
      }
  
      public string value2
      {
          set { this.dataGridView2.Rows[0].Cells[0].Value = value; }
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          Form2 form2 = new Form2();
          form2.Show();
          this.Hide();
      }
  
      private void button2_Click(object sender, EventArgs e)
      {
          Form3 form3 = new Form3();
          form3.Show();
          this.Hide();
      }
  </code></pre>
  
  <p>Form2:  </p>
  
  <pre><code>    public string exampleVal = "example";
  
      public string value
      {
          get { return exampleVal; }
      }
  
      private void button1_Click(object sender, EventArgs e)
      {
          Form1 frm = new Form1();
          frm.value1 = value;
          this.Hide();
          frm.ShowDialog();
      }
  </code></pre>
  
  <p>And Form3 has the same properties as above in Form2.</p>