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.
Unfortunately, activation email could not send to your email. Please try again.

How to navigate the current cell within the selected ranges like Excel when pressing Enter or Tab key in the GridDataControl?

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 the GridDataControl, but it doesn’t have a direct support.

To achieve this, you need to wire the PreviewKeyDown event in ModelLoaded event to handle the key navigation and SelectionChanging event to clear the selection when the current cell is out of the selected region based on the condition with local variable. You can wire these events as shown in the following code example.

C#

The PreviewKeyDown event for the GridDataControl is wired from the ModelLoaded event as shown in the following code example.

C#

With the help of SelectionChanging event, you can clear the selection when the current cell is clicked outside the selected ranges like Excel as shown in the following code example.

C#

Now, you can change the navigation behavior of Enter key from right to down like Excel by using the EnterKeyBehaviour.MouseDown in GridDataControl as shown in the following code example.

C#

With the help of the AlphaBend selection, you can achieve the selection format like Excel as shown in the following code example.

C#

The above AlphaBend selection is displayed in the GridDataControl as shown in the following screenshot.

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

You can get the ranges of selected region by using the SelectedRanges property in the GridDataControl. You need to check whether the current cell is maintained within that selected region or not. With the help of CurrencyManager, you can get the current cell’s row and column index in the GridDataControl as shown in the following code example.

C#

While pressing the Tab key, the next cell is automatically selected as a current cell and you can decide whether the current cell is inside or outside the selected region by comparing the above current cell row and column index with the SelectedRanges as shown in the following code example.

C#

Similarly, you can also check and handle navigation behavior when the Enter key is pressed as shown in the following code example.

C#

You can refer to the following sample link to navigate the current cell within the selected ranges of GridCell in WPF.

Link

http://www.syncfusion.com/downloads/support/directtrac/general/CustomizingSelection_GridDataControl_WPF502715471.zip

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

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.