'C# DataGridView Tab skip 1 Cell

I used this code to let the "Tab" Key get to the next Cell in the datagridview. The only problem is that it skips 1 Cell when the Cell enters in edit mode. here is the code:

 private void entityLinesGrid_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Tab)
            {
                e.SuppressKeyPress = true;
                int iColumn = entityLinesGrid.CurrentCell.ColumnIndex;
                int iRow = entityLinesGrid.CurrentCell.RowIndex;
                if (iColumn == entityLinesGrid.Columns.Count - 1)
                {
                    
                    entityLinesGrid.CurrentCell = entityLinesGrid[0, iRow + 1];
                }
                else {entityLinesGrid.CurrentCell = entityLinesGrid[iColumn + 1, iRow];}
            }

        }


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source