We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to navigate the current cell within the selected ranges as in Excel, while pressing Enter or Tab key in SfDataGrid?

In Excel, the current cell is navigated towards right for Tab key and down for Enter key within the selected region. You can also achieve the same requirement in SfDataGrid by deriving a new class from GridCellSelectionController and overriding the necessary virtual methods in SfDataGrid. You can refer to this link for more information about GridCellSelectionController and its available virtual method.

By using the Extended selection mode in SfDataGrid, you can achieve the selection format like in Excel as displayed in the following screenshot.

Figure 1: Default position of the current cell with in selected region

Note: You can change the behavior of Cell selection by overriding GridCellSelectionController class.

Assign the instance of GridCellSelectionControllerExt class that is derived from the GridCellSelectionController to SfDataGrid’s SelectionController property to customize the navigation behavior of current cell when Tab or Enter key is pressed as illustrated in the following code example.

C#

The different position of selected range is initialized while dragging selection in SfDataGrid .The ProcessDragSelection() virtual method is invoked while dragging selection in SfDataGrid. You can initialize the position of selected range by overriding the ProcessDragSelection() as illustrated in the following code example.

C#

In the above code example, the SetRange() private method is invoked and the Top, Left, Right, and Bottom position of selected range is initialized as illustrated in the following code example.

C#

You can customize the Enter and Tab key behavior of SfDataGrid by using ProcessKeyDown() virtual method of GridCellSelctionController as illustrated in the following code example.

C#

In the above code example, the default behavior is processed for Enter and Tab key navigation, when the current cell is not available with in selected range. By using CheckWithInRange() private method, you can identify whether the current cell is at selected range or out of the selected range as illustrated in the following code example.

C#

Once the current cell is clicked out of the range, it is not considered as selected range and the position of selected range is reset to default value, then the default navigation and selection behavior is processed.

The position of selected range is reset by using ResetRange() private method as illustrated in the following code example.

C#

The following code example illustrates on how to customize the navigation behavior of current cell when the Tab key is pressed in ProcessKeyDown virtual method of GridCellSelectionController.

C#

The following code example illustrates on how to customize the navigation behavior of current cell when the Enter key is pressed in ProcessKeyDown virtual method of GridCellSelectionController.

C#

By using HandlePointerOperations (), you can clear the position of selected range when the current cell is clicked without pressing Control key.

In SfDataGrid, the selection is removed when the already selected cell is selected again by using Control key. But in Excel, the selection is maintained. In this case, add selection externally to that cell by using AddSelection() method as illustrated in the following code example.

C#

 

Sample Links

WPF

WRT

UWP

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework: Product Version:
4668 04/22/2015 02/05/2016 WPF SfDataGrid 4.5 12.4.0.24
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon