protected override bool ShouldGridTryToHandlePreviewKeyDown(KeyEventArgs e) { // return false to indicate the CurrentCellUIElement should handle the key // and the grid should ignore it. bool isControlKey = (e.KeyboardDevice.Modifiers & ModifierKeys.Control) != ModifierKeys.None; if (isControlKey) { return(true); } switch (e.Key) { case Key.Right: case Key.Left: case Key.Down: case Key.Up: { return(!CurrentCell.IsEditing); } case Key.End: case Key.Home: { CurrentCell.BeginEdit(true); return(false); } case Key.Delete: { CurrentCell.BeginEdit(true); return(false); } case Key.Enter: { if (this.CurrentCell.IsEditing) { CurrentCell.EndEdit(); } CurrentCell.MoveRight(); return(true); } case Key.Back: { CurrentCell.BeginEdit(true); return(false); } } return(base.ShouldGridTryToHandlePreviewKeyDown(e)); }
protected override bool ShouldGridTryToHandlePreviewKeyDown(KeyEventArgs e) { // return false to indicate the CurrentCellUIElement should handle the key // and the grid should ignore it. bool isControlKey = (e.KeyboardDevice.Modifiers & ModifierKeys.Control) != ModifierKeys.None; if (isControlKey) { return(true); } switch (e.Key) { case Key.Right: case Key.Left: case Key.Down: case Key.Up: { // otherwise, move caret within textbox when cell is not in edit-mode. return(!CurrentCell.IsEditing); } case Key.End: case Key.Home: { CurrentCell.BeginEdit(true); return(false); } case Key.Delete: { CurrentCell.BeginEdit(true); return(false); } case Key.Enter: { if (this.CurrentStyle != null) { GridDataStyleInfo sif = this.CurrentStyle.GridModel[this.CurrentCell.RowIndex, this.CurrentCell.ColumnIndex] as GridDataStyleInfo; if (sif != null && sif.CellIdentity.TableCellType != GridDataTableCellType.AddNewRecordCell) { e.Handled = true; } else if (sif != null && sif.CellIdentity.TableCellType == GridDataTableCellType.AddNewRecordCell && !CurrentCell.IsEditing) { e.Handled = true; } } if (this.CurrentCell.IsEditing) { CurrentCell.EndEdit(); } CurrentCell.MoveRight(); return(true); break; } case Key.Back: { CurrentCell.BeginEdit(true); return(false); } break; } return(base.ShouldGridTryToHandlePreviewKeyDown(e)); }