title: How to evade reentrant call to setCurrentCellAddressCore?
body: <p>I have a function that is called from cell_endedit. It moves a dataGridViewRow inside a dataGridView:</p>
  
  <pre><code>private void moveRowTo(DataGridView table, int oldIndex, int newIndex)
  {
      if (newIndex &lt; oldIndex)
      {
          oldIndex += 1;
      }
      else if (newIndex == oldIndex)
      {
          return;
      }
      table.Rows.Insert(newIndex, 1);
      DataGridViewRow row = table.Rows[newIndex];
      DataGridViewCell cell0 = table.Rows[oldIndex].Cells[0];
      DataGridViewCell cell1 = table.Rows[oldIndex].Cells[1];
      row.Cells[0].Value = cell0.Value;
      row.Cells[1].Value = cell1.Value;
      table.Rows[oldIndex].Visible = false;
      table.Rows.RemoveAt(oldIndex);
      table.Rows[oldIndex].Selected = false;
      table.Rows[newIndex].Selected = true;
  }
  </code></pre>
  
  <p>at row table.Rows.Insert(newIndex, 1) i get the following error:</p>
  
  <blockquote>
    <p>Unhandled exception of type "System.InvalidOperationException" in
    System.Windows.Forms.dll</p>
    
    <p>Additional data: Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function.</p>
  </blockquote>
  
  <p>It happens when I click another cell in process of editing current cell.
  How do i evade such error and have my row inserted correctly?</p>