Articles in this section
Category / Section

How to change the PageUp and PageDown key behavior in WPF DataGrid?

4 mins read

WPF DataGrid (SfDataGrid) when you press the PageUp or PageDown key will be scrolled to the previous set of rows or the next set of rows that are not displayed in the view. To change this behavior like Tab key navigation that moves the currentcell to next cell of the same row by overriding GridCellSelectionController / GridSelectionController class and setting it to SfDataGrid.SelectionController property.

When SelectionUnit is a Cell, you have to override GridCellSelectionController and when SelectionUnit is Row, you have to override GridSelectionController class.

WPF DataGrid (SfDataGrid) is defined with SelectionUnit as Cell. You can change the PageUp and PageDown key behavior by overriding the ProcessKeyDown method in GridCellSelectionController in WPF DataGrid (SfDataGrid).

<syncfusion:SfDataGrid x:Name="sfDataGrid"  
                               SelectionMode="Single"
                               SelectionUnit="Cell"                              
                               ItemsSource="{Binding Orders}"
                               AutoGenerateColumns="False"/>

 

// set the customized GridCellSelectionControllserExt to SfDataGrid.SelectionController when CellSelection applied in SfDataGrid
this.sfDataGrid.SelectionController = new GridCellSelectionControllerExt(sfDataGrid);
 
 
//Inherits the GridCellSelectionController Class
public class GridCellSelectionControllerExt : GridCellSelectionController
{
        public GridCellSelectionControllerExt(SfDataGrid datagrid)
          : base(datagrid)
        {
        }
 
        //overriding the ProcessKeyDown Event from GridCellSelectionController base class
        protected override void ProcessKeyDown(KeyEventArgs args)
        {
            if (args.Key == Key.PageUp || args.Key == Key.PageDown)
            {
                //Key based Customization 
                KeyEventArgs arguments = new KeyEventArgs(args.KeyboardDevice, args.InputSource, args.Timestamp, Key.Tab) { RoutedEvent = args.RoutedEvent };
                base.ProcessKeyDown(arguments);
                //assigning the state of Tab key Event handling to PageUp and PageDown key
                args.Handled = arguments.Handled;
                return;
            }
            base.ProcessKeyDown(args);
        }
}

PageUp and PageDown key customization when Cell selection applied in SfDataGrid
WPF DataGrid (SfDataGrid) is defined with SelectionUnit as Row. You can change the PageUp and PageDown key behavior by overriding the ProcessKeyDown method in GridSelectionController in WPF DataGrid (SfDataGrid).

  <syncfusion:SfDataGrid x:Name="sfDataGrid"  
                               SelectionMode="Single"
                               SelectionUnit="Row"                              
                               ItemsSource="{Binding Orders}"
                               AutoGenerateColumns="False">

 

// set the customized GridSelectionControllserExt to SfDataGrid.SelectionController when RowSelection applied in SfDataGrid
this.sfDataGrid.SelectionController = new GridSelectionControllerExt(sfDataGrid);
 
//Inherits the GridSelectionController Class
public class GridSelectionControllerExt : GridSelectionController
{
        public GridSelectionControllerExt(SfDataGrid datagrid)
          : base(datagrid)
        {
        }
 
        //overriding the ProcessKeyDown Event from GridSelectionController base class
        protected override void ProcessKeyDown(KeyEventArgs args)
        {
            if (args.Key == Key.PageUp || args.Key == Key.PageDown)
            {
                //Key based Customization 
                KeyEventArgs arguments = new KeyEventArgs(args.KeyboardDevice, args.InputSource, args.Timestamp, Key.Tab) { RoutedEvent = args.RoutedEvent };
                base.ProcessKeyDown(arguments);
                //assigning the state of Tab key Event handling to PageUp and PageDown key
                args.Handled = arguments.Handled;
                return;
            }
            base.ProcessKeyDown(args);
        }
}

PageUp and PageDown key customization when Row selection applied in SfDataGrid
Take a moment to peruse the WPF DataGrid – Selection documentation, where you can find about selection with code examples.

You can download the example from GitHub.


Conclusion

I hope you enjoyed learning how to change the PageUp and PageDown key bahavior in WPF DataGrid.

You can refer to our WPDataGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF DataGrid example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied