protected override bool ShouldGridTryToHandleKeyDown(KeyEventArgs e)
        {
            if (e.Key != Key.Tab)
            {
                return(base.ShouldGridTryToHandleKeyDown(e));
            }

            bool      isShiftPressed        = SelectionHelper.CheckShiftKeyPressed();
            UIElement currentFocusedElement = Keyboard.FocusedElement as UIElement;
            var       currentCell           = this.DataGrid.SelectionController.CurrentCellManager.CurrentCell;
            var       columnElement         = currentCell.ColumnElement;

            //Column with Multiple controls inside DataTemplate.
            if (currentCell.GridColumn.MappingName != "SalesID")
            {
                return(base.ShouldGridTryToHandleKeyDown(e));
            }
            if (PreviousCurrentCellElement != columnElement && currentFocusedElement is SfDataGrid)
            {
                FocusNavigationDirection focusNavigationDirection = isShiftPressed ? FocusNavigationDirection.Last : FocusNavigationDirection.First;
                TraversalRequest         tRequest = new TraversalRequest(focusNavigationDirection);
                //To navigate from other column to template column
                if (columnElement.MoveFocus(tRequest))
                {
                    e.Handled = true;
                    PreviousCurrentCellElement = columnElement;
                    return(false);
                }
            }
            else
            {
                FocusNavigationDirection focusNavigationDirection = isShiftPressed ? FocusNavigationDirection.First : FocusNavigationDirection.Last;
                TraversalRequest         traversalRequest         = new TraversalRequest(focusNavigationDirection);
                if (columnElement.MoveFocus(traversalRequest))
                {
                    if (Keyboard.FocusedElement != currentFocusedElement)
                    {
                        Keyboard.Focus(currentFocusedElement);
                        PreviousCurrentCellElement = columnElement;
                        return(false);
                    }
                    //To navigate to other columns from template column
                    else
                    {
                        Keyboard.Focus(currentFocusedElement);
                        PreviousCurrentCellElement = null;
                        return(base.ShouldGridTryToHandleKeyDown(e));
                    }
                }
            }

            PreviousCurrentCellElement = columnElement;
            return(base.ShouldGridTryToHandleKeyDown(e));
        }
 /// <summary>
 /// Processes the row selection when the mouse pointer is released from SfDataGrid.
 /// </summary>
 /// <param name="args">
 /// Contains the data for mouse pointer action.
 /// </param>
 /// <param name="rowColumnIndex">
 /// The corresponding rowColumnIndex of the mouse released point.
 /// </param>
 /// <remarks>
 /// The selection is initialized in pointer released state when the <see cref="Syncfusion.UI.Xaml.Grid.SfDataGrid.AllowSelectionPointerPressed"/> set as false.
 /// </remarks>
 protected override void ProcessPointerReleased(PointerRoutedEventArgs args, RowColumnIndex rowColumnIndex)
 {
     if (SelectionHelper.CheckShiftKeyPressed() && this.PressedRowColumnIndex.RowIndex > 0)
     {
         this.SelectRows(this.PressedRowColumnIndex.RowIndex, rowColumnIndex.RowIndex);
     }
     else
     {
         base.ProcessPointerReleased(args, rowColumnIndex);
     }
 }
 /// <summary>
 /// Processes the row selection when the mouse pointer is released from SfDataGrid.
 /// </summary>
 /// <param name="args">
 /// Contains the data for mouse pointer action.
 /// </param>
 /// <param name="rowColumnIndex">
 /// The corresponding rowColumnIndex of the mouse released point.
 /// </param>
 /// <remarks>
 /// The selection is initialized in pointer released state when the <see cref="Syncfusion.UI.Xaml.Grid.SfDataGrid.AllowSelectionPointerPressed"/> set as false.
 /// </remarks>
 protected override void ProcessPointerReleased(MouseButtonEventArgs args, Syncfusion.UI.Xaml.ScrollAxis.RowColumnIndex rowColumnIndex)
 {
     if (SelectionHelper.CheckShiftKeyPressed() && this.PressedRowColumnIndex.RowIndex > 0)
     {
         this.SelectRows(this.PressedRowColumnIndex.RowIndex, rowColumnIndex.RowIndex);
     }
     else
     {
         base.ProcessPointerReleased(args, rowColumnIndex);
     }
 }
Beispiel #4
0
 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;
         }
     }
 }
Beispiel #5
0
        /// <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));
        }
Beispiel #7
0
        /// <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));
        }
        /// <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));
        }
Beispiel #9
0
        /// <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));
        }
Beispiel #10
0
        /// <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));
        }