/// <summary> /// Changes the flow direction of key navigation based on the <see cref="Windows.UI.Xaml.FlowDirection"/> in SfTreeGrid. /// </summary> /// <param name="currentKey"> /// Contains the key that was pressed. /// </param> protected internal void ChangeFlowDirectionKey(ref Key currentKey) { switch (currentKey) { case Key.Right: currentKey = Key.Left; break; case Key.Left: currentKey = Key.Right; break; case Key.Home: { if (!SelectionHelper.CheckControlKeyPressed()) { currentKey = Key.End; } } break; case Key.End: { if (!SelectionHelper.CheckControlKeyPressed()) { currentKey = Key.Home; } } break; } }
protected override void ProcessKeyDown(KeyRoutedEventArgs args) { base.ProcessKeyDown(args); if (args.Key == Windows.System.VirtualKey.V) { if (SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()) { (this.DataGrid.GridCopyPaste as CustomCopyPaste).PasteTextToRows(); args.Handled = true; } } }
/// <summary> /// Let Renderer decide whether the parent grid should be allowed to handle keys and prevent /// the key event from being handled by the visual UIElement for this renderer. If this method /// returns true the parent grid will handle arrow keys and set the Handled flag in the event /// data. Keys that the grid does not handle will be ignored and be routed to the UIElement /// for this renderer. /// </summary> /// <param name="e">A <see cref="KeyEventArgs" /> object.</param> /// <returns> /// True if the parent grid should be allowed to handle keys; false otherwise. /// </returns> protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e) { if (!HasCurrentCellState) { return(false); } var columnIndex = TreeGrid.ResolveToGridVisibleColumnIndex((this.CurrentCellElement as TreeGridCell).ColumnBase.ColumnIndex); var column = ((TreeGridTemplateColumn)TreeGrid.Columns[columnIndex]); var handleTemplatedUIElementKeyDown = FocusManagerHelper.GetWantsKeyInput(column); if ((column.hasCellTemplate || column.hasCellTemplateSelector) && (column.hasEditTemplate || column.hasEditTemplateSelector)) { handleTemplatedUIElementKeyDown = false; } switch (e.Key) { case Key.Space: return(!handleTemplatedUIElementKeyDown); case Key.A: case Key.V: case Key.X: case Key.C: { if (!handleTemplatedUIElementKeyDown && SelectionHelper.CheckControlKeyPressed() && !IsInEditing) { return(true); } break; } case Key.F2: case Key.Escape: { e.Handled = true; return(true); } case Key.Tab: // When press tab continuously and its reach to last one, then the focus goes to grid.Again if you press upo key, focus any of the content control. to avoid that the condition added. if (!IsInEditing && !(TreeGrid.GetLastDataRowIndex() == CurrentCellIndex.RowIndex && TreeGrid.SelectionController.CurrentCellManager.GetLastCellIndex() == CurrentCellIndex.ColumnIndex)) { // If Column with CellTemplate has editor loaded, then the click on that editor will not as we click or navigate to next cell, we need to remove the focus. base.SetFocus(CurrentCellRendererElement, false); } return(true); case Key.Enter: case Key.PageUp: case Key.PageDown: if (!IsInEditing) { // If Column with CellTemplate has editor loaded, then navigation of this key will set the focus. base.SetFocus(CurrentCellRendererElement, true); } return(true); case Key.Home: case Key.End: case Key.Down: case Key.Up: case Key.Left: case Key.Right: // if Column has WantsKeyInput Enabled the navigation should be in editor. { if (!handleTemplatedUIElementKeyDown && !IsInEditing) { base.SetFocus(CurrentCellRendererElement, false); return(true); } else if (handleTemplatedUIElementKeyDown) { return(false); } else { return(!IsInEditing); } } case Key.Delete: { if (handleTemplatedUIElementKeyDown) { return(false); } return(!IsInEditing); } } return(false); }
/// <summary> /// Let Renderer decide whether the parent grid should be allowed to handle keys and prevent /// the key event from being handled by the visual UIElement for this renderer. If this method /// returns true the parent grid will handle arrow keys and set the Handled flag in the event /// data. Keys that the grid does not handle will be ignored and be routed to the UIElement /// for this renderer. /// </summary> /// <param name="e">A <see cref="KeyEventArgs" /> object.</param> /// <returns> /// True if the parent grid should be allowed to handle keys; false otherwise. /// </returns> protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e) { if (!HasCurrentCellState || !IsInEditing) { return(true); } #if WPF var combobox = (CurrentCellRendererElement as ComboBox); TextBox comboTextBox = (TextBox)GridUtil.FindDescendantChildByType(combobox, typeof(TextBox)); #endif #if WPF if ((SelectionHelper.CheckAltKeyPressed() && e.SystemKey == Key.Down) || ((SelectionHelper.CheckAltKeyPressed() && e.SystemKey == Key.Up) || e.Key == Key.F4)) #else if ((SelectionHelper.CheckAltKeyPressed() && e.Key == Key.Down) || ((SelectionHelper.CheckAltKeyPressed() && e.Key == Key.Up) || e.Key == Key.F4)) #endif { var comboBox = ((ComboBox)CurrentCellRendererElement); comboBox.IsDropDownOpen = !comboBox.IsDropDownOpen; #if UWP comboBox.Focus(FocusState.Programmatic); #endif return(false); } switch (e.Key) { case Key.End: case Key.Home: case Key.Enter: case Key.Escape: return(!((ComboBox)CurrentCellRendererElement).IsDropDownOpen); case Key.Down: case Key.Up: #if UWP return(!((ComboBox)CurrentCellRendererElement).IsDropDownOpen); #endif #if WPF // WPF-25803 - Up/Down Needs to be handle by UiElement itself to change the selection whether drop down open or not/ IsEditable set or not set. return(false); case Key.Right: return(((ComboBox)CurrentCellRendererElement).IsEditable ? (comboTextBox.SelectionStart >= comboTextBox.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()) : true); case Key.Left: return(((ComboBox)CurrentCellRendererElement).IsEditable ? (comboTextBox.SelectionStart == comboTextBox.SelectionLength && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()) : true); #endif } return(base.ShouldGridTryToHandleKeyDown(e)); }
/// <summary> /// Let Renderer decide whether the parent grid should be allowed to handle keys and prevent /// the key event from being handled by the visual UIElement for this renderer. If this method /// returns true the parent grid will handle arrow keys and set the Handled flag in the event /// data. Keys that the grid does not handle will be ignored and be routed to the UIElement /// for this renderer. /// </summary> /// <param name="e">A <see cref="KeyEventArgs" /> object.</param> /// <returns> /// True if the parent grid should be allowed to handle keys; false otherwise. /// </returns> protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e) { if (!HasCurrentCellState) { return(true); } if (!IsInEditing) { #if UWP ProcessPreviewTextInput(e); if (!(CurrentCellRendererElement is SfNumericTextBox)) { return(true); } #else return(true); #endif } var CurrentCellUIElement = (DoubleTextBox)CurrentCellRendererElement; switch (e.Key) { case Key.Escape: { CurrentCellUIElement.ClearValue(DoubleTextBox.ValueProperty); return(true); } case Key.Left: return(CurrentCellUIElement.SelectionStart == CurrentCellUIElement.SelectionLength && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Right: return(CurrentCellUIElement.SelectionStart >= CurrentCellUIElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Home: return(CurrentCellUIElement.SelectionStart == CurrentCellUIElement.SelectionLength && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.End: return(CurrentCellUIElement.SelectionStart == CurrentCellUIElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); #if WPF //WPF-18339- When navigating by Up or Down key, should return here if IsScrollingOnCircle is true for that UIElement case Key.Up: case Key.Down: return(!CurrentCellUIElement.IsScrollingOnCircle); #endif } return(base.ShouldGridTryToHandleKeyDown(e)); }
/// <summary> /// Shoulds the grid try automatic handle key down. /// </summary> /// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param> /// <returns></returns> protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e) { if (!HasCurrentCellState || !IsInEditing) { return(true); } var CurrentCellUIElement = (PercentTextBox)CurrentCellRendererElement; switch (e.Key) { case Key.Escape: { if (CurrentCellUIElement != null) { CurrentCellUIElement.ClearValue(PercentTextBox.PercentValueProperty); } return(true); } case Key.Left: return(CurrentCellUIElement.SelectionStart == CurrentCellUIElement.SelectionLength && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Right: return(CurrentCellUIElement.SelectionStart >= CurrentCellUIElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Home: return(CurrentCellUIElement.SelectionStart == CurrentCellUIElement.SelectionLength && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.End: return(CurrentCellUIElement.SelectionStart == CurrentCellUIElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); //WPF-18339- When navigating by Up or Down key, should return here if IsScrollingOnCircle is true for that UIElement case Key.Up: case Key.Down: return(!CurrentCellUIElement.IsScrollingOnCircle); } return(base.ShouldGridTryToHandleKeyDown(e)); }
internal void ProcessPreviewTextInput(KeyEventArgs e) { if ((!char.IsLetterOrDigit(e.Key.ToString(), 0) || !TreeGrid.AllowEditing || TreeGrid.NavigationMode != NavigationMode.Cell) || SelectionHelper.CheckControlKeyPressed() || (!(e.Key >= Key.A && e.Key <= Key.Z) && !(e.Key >= Key.Number0 && e.Key <= Key.Number9) && !(e.Key >= Key.NumberPad0 && e.Key <= Key.NumberPad9))) { return; } if (TreeGrid.SelectionController.CurrentCellManager.BeginEdit()) { PreviewTextInput(e); } }
internal void MakeSort(TreeGridColumn column) { if (this.View == null) { return; } if (column.MappingName == null) { throw new InvalidOperationException("Mapping Name is necessary for Sorting"); } if (!this.treeGrid.CheckColumnNameinItemProperties(column)) { return; } CommitCurrentRow(); var sortColumName = column.MappingName; var cancelScroll = false; var allowMultiSort = SelectionHelper.CheckControlKeyPressed(); IsInSort = true; if (treeGrid.SortColumnDescriptions.Any() && allowMultiSort) { var sortedColumn = this.treeGrid.SortColumnDescriptions.FirstOrDefault(s => s.ColumnName == sortColumName); if (sortedColumn == default(SortColumnDescription)) { var newSortColumn = new SortColumnDescription { ColumnName = sortColumName, SortDirection = ListSortDirection.Ascending }; if (this.treeGrid.RaiseSortColumnsChanging(new List <SortColumnDescription>() { newSortColumn }, new List <SortColumnDescription>(), NotifyCollectionChangedAction.Add, out cancelScroll)) { this.treeGrid.SortColumnDescriptions.Add(newSortColumn); this.treeGrid.RaiseSortColumnsChanged(new List <SortColumnDescription>() { newSortColumn }, new List <SortColumnDescription>(), NotifyCollectionChangedAction.Add); } } else { if (sortedColumn.SortDirection == ListSortDirection.Descending && this.treeGrid.AllowTriStateSorting) { var removedSortColumn = this.treeGrid.SortColumnDescriptions.FirstOrDefault(s => s.ColumnName == sortColumName); if (removedSortColumn != null) { if (this.treeGrid.RaiseSortColumnsChanging(new List <SortColumnDescription>(), new List <SortColumnDescription>() { removedSortColumn }, NotifyCollectionChangedAction.Remove, out cancelScroll)) { this.treeGrid.SortColumnDescriptions.Remove(removedSortColumn); this.treeGrid.RaiseSortColumnsChanged(new List <SortColumnDescription>(), new List <SortColumnDescription>() { removedSortColumn }, NotifyCollectionChangedAction.Remove); } } } else { sortedColumn.SortDirection = sortedColumn.SortDirection == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending; var removedSortColumn = this.treeGrid.SortColumnDescriptions.FirstOrDefault(s => s.ColumnName == sortedColumn.ColumnName); if (this.treeGrid.RaiseSortColumnsChanging(new List <SortColumnDescription> { sortedColumn }, new List <SortColumnDescription>() { removedSortColumn }, NotifyCollectionChangedAction.Replace, out cancelScroll)) { this.treeGrid.SortColumnDescriptions.Remove(removedSortColumn); this.treeGrid.SortColumnDescriptions.Add(sortedColumn); this.treeGrid.RaiseSortColumnsChanged(new List <SortColumnDescription> { sortedColumn }, new List <SortColumnDescription>() { removedSortColumn }, NotifyCollectionChangedAction.Replace); } } } } else { var currentSortColumn = this.treeGrid.SortColumnDescriptions.FirstOrDefault(s => s.ColumnName == sortColumName); if (currentSortColumn != default(SortColumnDescription)) { if (currentSortColumn.SortDirection == ListSortDirection.Descending && this.treeGrid.AllowTriStateSorting) { var sortColumnsClone = this.treeGrid.SortColumnDescriptions.ToList(); if (this.treeGrid.RaiseSortColumnsChanging(new List <SortColumnDescription>(), sortColumnsClone, NotifyCollectionChangedAction.Remove, out cancelScroll)) { this.treeGrid.SortColumnDescriptions.Clear(); this.treeGrid.RaiseSortColumnsChanged(new List <SortColumnDescription>(), sortColumnsClone, NotifyCollectionChangedAction.Remove); } } else { currentSortColumn.SortDirection = currentSortColumn.SortDirection == ListSortDirection.Ascending ? ListSortDirection.Descending : ListSortDirection.Ascending; if (this.treeGrid.RaiseSortColumnsChanging(new List <SortColumnDescription>() { currentSortColumn }, new List <SortColumnDescription>(), NotifyCollectionChangedAction.Replace, out cancelScroll)) { this.treeGrid.SortColumnDescriptions.Clear(); this.treeGrid.SortColumnDescriptions.Add(currentSortColumn); this.treeGrid.RaiseSortColumnsChanged(new List <SortColumnDescription>() { currentSortColumn }, new List <SortColumnDescription>(), NotifyCollectionChangedAction.Replace); } } } else { var sortColumn = new SortColumnDescription() { ColumnName = sortColumName, SortDirection = ListSortDirection.Ascending }; if (this.treeGrid.SortColumnDescriptions.Any()) { var sortColumnsClone = this.treeGrid.SortColumnDescriptions.ToList(); if (this.treeGrid.RaiseSortColumnsChanging(new List <SortColumnDescription>() { sortColumn }, sortColumnsClone, NotifyCollectionChangedAction.Add, out cancelScroll)) { this.treeGrid.SortColumnDescriptions.Clear(); this.treeGrid.SortColumnDescriptions.Add(sortColumn); this.treeGrid.RaiseSortColumnsChanged(new List <SortColumnDescription>() { sortColumn }, sortColumnsClone, NotifyCollectionChangedAction.Add); } } else { if (this.treeGrid.RaiseSortColumnsChanging(new List <SortColumnDescription>() { sortColumn }, new List <SortColumnDescription>(), NotifyCollectionChangedAction.Add, out cancelScroll)) { this.treeGrid.SortColumnDescriptions.Add(sortColumn); this.treeGrid.RaiseSortColumnsChanged(new List <SortColumnDescription>() { sortColumn }, new List <SortColumnDescription>(), NotifyCollectionChangedAction.Add); } } } } RefreshAfterSorting(cancelScroll); IsInSort = false; }
/// <summary> /// Let Renderer decide whether the parent grid should be allowed to handle keys and prevent /// the key event from being handled by the visual UIElement for this renderer. If this method /// returns true the parent grid will handle arrow keys and set the Handled flag in the event /// data. Keys that the grid does not handle will be ignored and be routed to the UIElement /// for this renderer. /// </summary> /// <param name="e">A <see cref="KeyEventArgs" /> object.</param> /// <returns> /// True if the parent grid should be allowed to handle keys; false otherwise. /// </returns> protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e) { #if WPF if (!HasCurrentCellState || !IsInEditing) { return(true); } var currentCellUiElement = (MaskedTextBox)CurrentCellRendererElement; switch (e.Key) { case Key.Escape: { currentCellUiElement.ClearValue(MaskedTextBox.ValueProperty); return(true); } case Key.F2: { if (!IsInEditing) { TreeGrid.Focus(); } return(true); } case Key.A: return(SelectionHelper.CheckControlKeyPressed() && !IsInEditing); case Key.Left: return(currentCellUiElement.SelectionStart == currentCellUiElement.SelectionLength && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Right: return(currentCellUiElement.CaretIndex >= currentCellUiElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Home: return(currentCellUiElement.SelectionStart == currentCellUiElement.SelectionLength && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.End: return(currentCellUiElement.CaretIndex == currentCellUiElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); } #else if (!HasCurrentCellState) { return(true); } if (!IsInEditing) { ProcessPreviewTextInput(e); if (!(CurrentCellRendererElement is SfMaskedEdit)) { return(true); } } var currentCellUiElement = (SfMaskedEdit)CurrentCellRendererElement; switch (e.Key) { case Key.Escape: { currentCellUiElement.ClearValue(SfMaskedEdit.TextProperty); return(true); } } #endif return(base.ShouldGridTryToHandleKeyDown(e)); }
/// <summary> /// Let Renderer decide whether the parent grid should be allowed to handle keys and prevent /// the key event from being handled by the visual UIElement for this renderer. If this method /// returns true the parent grid will handle arrow keys and set the Handled flag in the event /// data. Keys that the grid does not handle will be ignored and be routed to the UIElement /// for this renderer. /// </summary> /// <param name="e">A <see cref="KeyEventArgs" /> object.</param> /// <returns> /// True if the parent grid should be allowed to handle keys; false otherwise. /// </returns> protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e) { #if UWP if (!HasCurrentCellState) { return(true); } if (!IsInEditing) { ProcessPreviewTextInput(e); if (!(CurrentCellRendererElement is TextBox)) { return(true); } } #else if (!HasCurrentCellState || !IsInEditing) { return(true); } #endif var CurrentCellUIElement = (TextBox)CurrentCellRendererElement; switch (e.Key) { case Key.Escape: { CurrentCellUIElement.ClearValue(TextBox.TextProperty); return(true); } #if WPF case Key.Left: return(CurrentCellUIElement.SelectionStart == CurrentCellUIElement.SelectionLength && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Right: return(CurrentCellUIElement.CaretIndex >= CurrentCellUIElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Home: return(CurrentCellUIElement.SelectionStart == CurrentCellUIElement.SelectionLength && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.End: return(CurrentCellUIElement.CaretIndex == CurrentCellUIElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); #endif } return(base.ShouldGridTryToHandleKeyDown(e)); }
/// <summary> /// Let Renderer decide whether the parent grid should be allowed to handle keys and prevent /// the key event from being handled by the visual UIElement for this renderer. If this method /// returns true the parent grid will handle arrow keys and set the Handled flag in the event /// data. Keys that the grid does not handle will be ignored and be routed to the UIElement /// for this renderer. /// </summary> /// <param name="e">A <see cref="KeyEventArgs" /> object.</param> /// <returns> /// True if the parent grid should be allowed to handle keys; false otherwise. /// </returns> protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e) { #if UWP if (!HasCurrentCellState) { return(true); } if (!IsInEditing) { ProcessPreviewTextInput(e); if (!(CurrentCellRendererElement is SfDatePicker)) { return(true); } } #else if (!HasCurrentCellState || !IsInEditing) { return(true); } #endif var CurrentCellUIElement = (DateTimeEdit)CurrentCellRendererElement; switch (e.Key) { #if !UWP case Key.F4: { if (CurrentCellUIElement.IsDropDownOpen) { CurrentCellUIElement.ClosePopup(); } else { CurrentCellUIElement.OpenPopup(); } return(true); } #endif case Key.Escape: { #if !UWP if (CurrentCellUIElement != null) { CurrentCellUIElement.ClearValue(DateTimeEdit.DateTimeProperty); } #endif //TODO: Asked Tools Team Checking DropDown is Open or Not //If DropDown is Open, we need to close the DropDown and should not End Edit (return false) //else return true to EndEdit //Currently we are returning true to end edit the DateTime Cell to stop the Exception that arises at UpdateSource of BindingExpression return(true); } case Key.Up: case Key.Down: return(!IsInEditing); #if WPF case Key.Left: return(CurrentCellUIElement.CaretIndex <= 0 && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Right: return((CurrentCellUIElement.SelectionLength + CurrentCellUIElement.SelectionStart) >= CurrentCellUIElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.Home: return(CurrentCellUIElement.SelectionStart == 0 && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); case Key.End: return(CurrentCellUIElement.CaretIndex == CurrentCellUIElement.Text.Length && !SelectionHelper.CheckControlKeyPressed() && !SelectionHelper.CheckShiftKeyPressed()); #else case Key.Left: case Key.Right: return(true); #endif } return(base.ShouldGridTryToHandleKeyDown(e)); }