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

Detecting Lost Focus to commit changes

I have a spreadsheet and it has some dropdown list validation.   I want to detect when the spreadsheet or cell loses focus such as when I click a button outside of the grid so that I can then commit that value.

The spreadsheet lost focus event doesnt seem to be the one to use or it doesnt fire when I'm expecting it to.



3 Replies

AA Arulraj A Syncfusion Team February 22, 2019 04:28 AM

Hi Spotty, 

Thanks for using Syncfusion product. 

By default, If cell is in edit mode, focus will not loss until you commit the value using press the enter key or navigate to next cell. This is the excel behavior.  To achieve your reported scenario, you could implement the custom cell renderer for SpreadsheetTextBoxCellRenderer and override the OnEditElementLostFocus method. Please refer the following code example and the sample. 

VB 
AddHandler Me.spreadsheet.WorkbookLoaded, AddressOf Spreadsheet_WorkbookLoaded 
 
Private Sub Spreadsheet_WorkbookLoaded(ByVal sender As Object, ByVal args As Syncfusion.Windows.Forms.Spreadsheet.Helpers.WorkbookLoadedEventArgs) 
    Me.spreadsheet.ActiveGrid.CellRenderers("TextBox") = New CustomTextBoxCellRenderer() 
End Sub 
 
Partial Class CustomTextBoxCellRenderer 
    Inherits Syncfusion.Windows.Forms.Spreadsheet.CellRenderer.SpreadsheetTextBoxCellRenderer 
    Public Sub New() 
    End Sub 
 
    Protected Overrides Sub OnEditElementLostFocus(sender As Object, e As EventArgs) 
        MyBase.OnEditElementLostFocus(sender, e) 
        'To commit the cell value. 
        Me.Grid.CurrentCell.EndEdit() 
    End Sub 
End Class 
 
 
 
Please get back to us if you need any further assistance on this. 

Arulraj A 



SP Spotty March 27, 2019 05:58 PM

Im not sure that you have the right scenario here.   I have some data validation on a cell - resulting in a dropdown list box.   When I click on a button outside the spreadsheet control I want to commit the edit into the spreadsheet prior to performing the button click code.

The code same works when I click out of dropdown to another cell in the spreadsheet but not when I click on a control outside of the sheet - when I also want to commit the edit prior to carrying out the action. 

Attachment: UpdateLostfocus_b1f5fff9.zip


MG Mohanraj Gunasekaran Syncfusion Team March 28, 2019 08:56 AM

Hi Spotty,  
 
Thanks for your update. 
 
The reported scenario is default excel behavior. If you use the ComboBox column for cell, the cell values will not commit until click on any cell. So, we can’t change this behavior. Please find the following excel video demo link 
 
 
Please get back to us if you need any further assistance on this. 
 
Regards, 
Mohanraj G 


Loader.
Live Chat Icon For mobile
Up arrow icon