New to Telerik UI for WPF? Download free 30-day trial

Cancel Edit On LostFocus

The RadGridView control exposes an ActionOnLostFocus property which allows you to control what happens when the control loses the focus.

The ActionOnLostFocus enumeration has three possible values:

  • CancelEdit: When the focus of a field in edit mode is lost, its edit mode will be canceled.
  • CommitEdit: When the focus of a field in edit mode is lost, its contents will be validated.
  • None: When the focus of an element is lost, no specific action will be taken.

The default value of the property is CommitEdit meaning that all changes will be commited when the control loses focus.

Let's say, for example, that you want to have two buttons outside of your RadGridView which are bound to the CommitEdit and CancelRowEdit commands.

Example 1: Buttons Bound to RadGridView Commands

<Button Content="Confirm"  
        CommandTarget="{Binding ElementName=GridView}"/> 
<Button Content="Cancel"  
        CommandTarget="{Binding ElementName=GridView}"/> 
With the default behavior, once you edit a cell and click the "Cancel" button, the changes will be actually committed, because RadGridView loses focus prior to the command being executed.

Figure 1: RadGridView with default ActionOnLostFocus

Telerik WPF DataGrid action-on-lost-focus-commitedit

To overcome this, you can simply set the ActionOnLostFocus property to None.

Example 2: Set ActionOnLostFocus to None

<telerik:RadGridView ActionOnLostFocus="None" ...> 
This way the "Cancel" button will work as expected as illustrated on Figure 2.

Figure 2: RadGridView with ActionOnLostFocus set to None

Telerik WPF DataGrid action-on-lost-focus-none

See Also

In this article