if (e.KeyCode == Keys.Down) { int c = userControl11.CurrentCell.ColumnIndex; int r = userControl11.CurrentCell.RowIndex; if (r < userControl11.Rows.Count - 1) //check for index out of range userControl11.CurrentCell = userControl11[c, r + 1]; } if (e.KeyCode == Keys.Up) { int c = userControl11.CurrentCell.ColumnIndex; int r = userControl11.CurrentCell.RowIndex; if (r > 0) //userControl11 for index out of range userControl11.CurrentCell = userControl11[c, r - 1]; } if (e.KeyCode == Keys.Back || e.KeyCode == Keys.Left) { //to check if you are in first cell of any line if (iColumn == 0) { //to check if you are in first cell of fist line if (iRow == 0) { MessageBox.Show("you reached first cell"); } else { userControl11.CurrentCell = userControl11[userControl11.ColumnCount - 1, iRow - 1]; } } else { userControl11.CurrentCell = userControl11[iColumn - 1, iRow]; } }