title: An unhandled exception of type 'System.InvalidCastException' occurred in UretimPlan.exe
body: <p>I'm developing a project to transfer selected rows between two datagridviews.
  however, when I run the project and press the button that allows me to drop the selected rows from the parent table to the child table, I get the following error. I would be glad if you help.</p>
  <p><img src="https://i.stack.imgur.com/Aks33.png" alt="This view" /></p>
  <pre><code>private void button2_Click(object sender, EventArgs e)
      {
          dataGridView2.Rows.Clear(); 
          foreach (DataGridViewRow item in dataGridView1.Rows)
          {
              if ((bool)item.Cells[0].Value==true)
              {
                  int n = dataGridView2.Rows.Add();
                  dataGridView2.Rows[n].Cells[0].Value = item.Cells[1].Value.ToString();
                  dataGridView2.Rows[n].Cells[1].Value = item.Cells[2].Value.ToString();
                  dataGridView2.Rows[n].Cells[2].Value = item.Cells[3].Value.ToString();
                  dataGridView2.Rows[n].Cells[3].Value = item.Cells[4].Value.ToString();
                  dataGridView2.Rows[n].Cells[4].Value = item.Cells[5].Value.ToString();
                  dataGridView2.Rows[n].Cells[5].Value = ((DateTime)item.Cells[6].Value).ToString(&quot;MM-dd-yyyy&quot;);
                  dataGridView2.Rows[n].Cells[6].Value = item.Cells[7].Value.ToString();
                 
              }
          }
      }
  </code></pre>
  <p>the error is in this line</p>
  <pre class="lang-cs prettyprint-override"><code>dataGridView2.Rows[n].Cells[5].Value = ((DateTime)item.Cells[6].Value).ToString(&quot;MM-dd-yyyy&quot;);
  </code></pre>
  <p>Also, when I transfer the selected rows to the other table, I want it to be deleted from that table in my database. How can I do that ?</p>
  <p><a href="https://i.stack.imgur.com/RVdue.png" rel="nofollow noreferrer">View</a></p>