title: How to move selected rows from one datagridview to another datagridview in c#?
body: <p>I tried this code to move selected rows from datagridview2 to datagridview1.But when I clicked to add button to move selected rows from datagridview2. And it also added to datagridview 2.But an error occurred through exception which is "<strong>Object reference not set to an instance of an object</strong>".How to solve this. My code as follows</p>
  
  <pre><code> private void button1_Click(object sender, EventArgs e)
      {
  
          try
          {
              this.dataGridView1.Rows.Clear();
              foreach (DataGridViewRow row in dataGridView2.Rows)
              {
                  int n = dataGridView1.Rows.Add();
                  bool checkedCell = (bool)dataGridView2.Rows[n].Cells[0].Value;
                  if (checkedCell == true)
                  {
                      dataGridView1.Rows[n].Cells[0].Value = row.Cells[1].Value;
                      dataGridView1.Rows[n].Cells[1].Value = row.Cells[2].Value;
                      dataGridView1.Rows[n].Cells[3].Value = row.Cells[3].Value;
                  }
  
              }
  
          }
          catch (Exception ex)
          {
              MessageBox.Show(" Error " + ex.Message);
          }
      }
  </code></pre>
  
  <p>I need to do this.But data should load by clicking load button
  <a href="https://i.stack.imgur.com/9x65m.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9x65m.jpg" alt="enter image description here"></a></p>