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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to change the Enter key behavior to insert line break when the CurrentCell is in the edit mode?

Platform: UWP |
Control: SfDataGrid |
Published Date: January 21, 2016 |
Last Revised Date: January 21, 2016 |
.NET Framework: 4.5

In SfDataGrid, by default when you press Enter key, the CurrentCell moves to next row. To change this behavior like inserting a line break by pressing the Enter key when the CurrentCell is in the edit mode, you can change this Enter key behavior by overriding GridCellSelectionController / GridSelectionController class and setting it to SfDataGrid.SelectionController property.

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

You can insert the line break within the TextBox by setting AcceptsReturn to true. AcceptsReturn property allows you to use the TextBox as a multiline input field.

In the following code example, SfDataGrid is defined with SelectionUnit as Cell and Style for TextBox within SfDataGrid.Resources.ResourceDictionary is defined by setting AcceptsReturn to true.


The following code example shows you how to set the instance of GridCellSelectionControllerExt that is derived from GridCellSelectionController to SfDataGird.SelectionController property.


The following code example explains you how to override the GridCellSelectionController class.


By default SfDataGrid handles Enter key. You can change this behavior by setting KeyEventArgs.Handled to false in ProcessKeyDown override method as in the following code example.


Note: For WinRT platform, no need to override GridCellSelectionController / GridSelectionController. Setting AcceptsReturn property as True to TextBox within SfDataGrid.Resources.ResourceDictionary enables multiline input.

In the following screenshot SfDataGrid allows you to enter multiline inputs while editing.




Sample Links:





2X faster development

The ultimate UWP UI toolkit to boost your development speed.
You must log in to leave a comment
Ondrej Svoboda
Jun 16, 2017
When I change in your example selection unit to row (SelectionUnit="Row") I'm getting strange results (whole row should be gray).

When I comment out custom selection controller:
//this.sfdatagrid.SelectionController = new GridCellSelectionControllerExt(sfdatagrid);
then I get expected results:

Do you have and idea what is causing the problem?
Ondrej Svoboda
Jun 16, 2017
I was testing WPF sample.
Ondrej Svoboda
Jun 16, 2017
Sorry, I didn't read cerefully the text. O fcourse I need to override GridSelectionController instead GridCellSelectionController .

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

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

Live Chat Icon For mobile