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 handle keyboard and mouse interactions for GridTemplateColumn?

In SfDataGrid, while using the TemplateColumn you cannot handle key navigation, mouse interaction and focusing for controls loaded within DataTemplate by default. This is because, as you can load any control within the DataTemplate, it is not possible to focus on the control loaded within the DataTemplate by default. Hence, GridTemplateColumn provides the list of attached property to handle key navigation, mouse interaction, focusing for loaded controls within DataTemplate. You can get the following attached properties in Syncfusion.UI.Xaml.Grid namespace.

  • FocusManagerHelper.FocusedElement
  • FocusManagerHelper.WantsKeyInput
  • VisualContainer.WantsMouseInput

 

Thus, in order to enter edit mode using keyboard you need to set focus to the control loaded inside the DataTemplate explicitly. To set the focus to the control loaded inside the DataTemplate you can use the attached property, FocusedElement.

FocusedElement

The attached property FocusedElement gives focus to particular UIElement loaded inside the DataTemplate. So, you can enter edit mode using keyboard itself.

The following code sample shows, how to set the FocusedElement inside DataTemplate

XAML

 

WantsKeyInput

The attached property allows the controls loaded in CellTemplate to handle key navigation within it or by Grid. When you set it to false’, you cannot navigate using keys within the loaded control.

Note: Enter and Tab keys are always handled by Grid only.

The following code sample explains you about WantsKeyInput.

XAML

 

WantsMouseInput

The attached property allows the controls loaded in CellTemplate to handle mouse interaction within it or by Grid.

The following code example explains you about WantsMouseInput

XAML

 

In addition to the above attached properties, you can set focused element by using FocusManager. FocusedElement attached property which comes in WPF framework can be used only for EditTemplate and not for editing inside the CellTemplate.

 

Sample Link:

WPF

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework:
2433 08/06/2014 01/19/2016 WPF SfDataGrid 4.5
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.