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: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

End SfDatagrid edition when losing focus

Thread ID:





121932 Feb 9,2016 05:00 PM UTC May 3,2016 06:21 PM UTC WPF 3
Tags: SfDataGrid
Carlos Fernando Consigli
Asked On February 9, 2016 05:00 PM UTC

Hi. I'm working on an app which has many SfDataGrids, each one inside an expander, and many of these expanders in different tabs.
I have some behaviour on the CurrentCellEndEdit event for every SfDataGrid but what I'm trying to accomplish is to prevent two or more SfDataGrids being in edit mode at the same time. Moreover, I need to force end edit when the user switches to a different tab than the current (this is the same way Excel finishes edition of a cell when you click in another worksheet).
I have tried to do it on LostFocus event, but for some reason this event is triggered a couple times when the edition is starting, and then one when the grid is actually losing focus. I guess this has to do with the editing textbox control gaining focus and the main element grid "losing it".
The problem is that I haven't found a way to distinguish the "real" LostFocus (the last one) which is the one in which the grid is actually losing the focus. This
is true in at least one of the first triggers of the LostFocus event when the edition is beginning.

Is there any way to force the grid to end edit when losing focus? Maybe I'm taking the wrong approach trying to do it in the LoseFocus event.
Thanks in advance.


Jayapradha S [Syncfusion]
Replied On February 10, 2016 12:41 PM UTC

Hi Fernando,

Thank you for using Syncfusion products.

In TabControl.SelectionChanged event, you can end edit the current cell of SfDataGrid when swithching to different tab item.. It is not possible to achieve this by using Lost focus event. As each time the focus is changed between tab items, sfdatagrid and its elements. Please try with the below code,

Code Example:

tabControl.SelectionChanged += tabControl_SelectionChanged;     


void tabControl_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)


            var removedItems = e.RemovedItems;

            foreach(var removedItem in removedItems)


                var expander = (removedItem as TabItem).Content as Expander;

                var grid = expander.Content as SfDataGrid;

                if (grid != null && grid.SelectionController.CurrentCellManager.CurrentCell != null && grid.SelectionController.CurrentCellManager.CurrentCell.IsEditing)



For your reference, have attached the sample below,

Sample Link:

Please let us know if you have any query.



Carlos Fernando Consigli
Replied On May 1, 2016 09:08 PM UTC

Thanks for your answer and sorry for the delay updating, I had to put aside this issue for a while.
The problem is that not only I have to end edition when moving to another tab, but also when switching focus to another grid in the same tab and even when clicking in some ribbon buttons the application has.
But I will try to apply your solution adapting that code and calling it in all focus events of components that should trigger end of edition and see if it works.

Srinivasan Vasu [Syncfusion]
Replied On May 3, 2016 06:21 PM UTC

Hi Fernando, 
Sorry for delay caused. 
We have analyzed your query. You can achieve your requirement using SfDataGrid.LostKeyboardFocus event in SfDataGrid where the event will be raised when losing the Keyboard focus from SfDataGrid. While using ribbon buttons, the focus will be remained same in SfDataGrid which is the default behavior. Hence the lost focus will not works for ribbon buttons. Please refer the below code example. 
// KeyBoard Lost Focus Event 
  this.datagrid.LostKeyboardFocus += DataGrid_LostKeyboardFocus; 
void dataGrid1_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) 
            if (!this.dataGrid1.IsKeyboardFocusWithin) 

Please download the sample from below location. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

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

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