title: DataGridView1.CurrentCell and BeginEdit doesn't work if I move with Tab
body: <p>C#, WinForms.</p>
  
  <p>Maybe it's a stupid and trivial problem but I can not get out!
  I have a <code>DataGridView1</code>with 4 columns. I check if the value of each row, in column 1, is identical to the value of the previous row in column 2. If yes, a <code>MessageBox</code> appears to inform me ... and I want to bring the focus to the cell in which there is the double value just entered. I therefore wrote this code:</p>
  
  <pre><code>private void DataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs cella)
  {
      if (cella.RowIndex &gt; 0 &amp;&amp; cella.ColumnIndex == 1)
      {
          var PrevCell = DataGridView1.Rows[cella.RowIndex - 1].Cells[2].Value.ToString();
          if (DataGridView1.Rows[cella.RowIndex].Cells[cella.ColumnIndex].Value.ToString() == PrevCell)
          {
              MessageBox.Show("Amount already exists. Change the current value or the previous occurrence", "Double value, already inserted", MessageBoxButtons.OK, MessageBoxIcon.Warning);
              DataGridView1.CurrentCell = DataGridView1.Rows[cella.RowIndex].Cells[cella.ColumnIndex];
              DataGridView1.BeginEdit(true);
              //only a test:
              //return;
              }
          }
      }
  }
  </code></pre>
  
  <p>And the <code>CurrentCell</code> works fine. The problem is that such control is carried out with the <code>CellEndEdit</code> Event, when I press the <code>Tab</code> key to move to the next cell (or I click with the mouse to the next cell) and therefore, even if the <code>BeginEdit</code> placed me on the right cell for let me edit the value, as soon as I press Tab again, it move the changed value in the next cell. It seems that the Tab pressed before displaying the MessageBox remains in memory. </p>
  
  <p>When I'm writing a double value, and MessageBox appears
  <a href="https://i.stack.imgur.com/E4SmL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E4SmL.png" alt="When I&#39;m writing a double value, and MessageBox appears"></a></p>
  
  <p>When the CurrentCell and BeginEdit lead me in the correct cell to change the double value
  <a href="https://i.stack.imgur.com/B8vHt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/B8vHt.png" alt="When the CurrentCell and BeginEdit lead me in the correct cell to change the double value"></a></p>
  
  <p>At the end of the Event</p>
  
  <p><a href="https://i.stack.imgur.com/PAQbx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PAQbx.png" alt="At the end of the Event"></a></p>
  
  <p>Any idea on how to handle the problem?</p>