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

How to know if spreadsheet has been modified?

Thread ID:

Created:

Updated:

Platform:

Replies:

150804 Jan 20,2020 07:35 PM UTC Jan 22,2020 10:19 AM UTC WinForms 4
loading
Tags: Spreadsheet
Chris
Asked On January 20, 2020 07:35 PM UTC

Hi, I would like to know if there is a way to know if a spreadsheet is modified - such as if user wants to close the application, prompt the user to save spreadsheet if it has  been modified? 

Thank you.


Arulpriya Ramalingam [Syncfusion]
Replied On January 21, 2020 08:52 AM UTC

Hi Chris, 
 
Thank you for using Syncfusion products. 
 
By default, the Spreadsheet for WinForms will popup a messagebox when the spreadsheet contents are modified to save the changes or not. The action can be manually invoked by using the FileClose command of Spreadsheet when the form is closing. Please make use of below code. 
 
Example code 
 
//Event subscription. 
this.FormClosing += Form1_FormClosing; 
 
//Event customization 
private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
{ 
    spreadsheet.Commands.FileClose.Execute(this.spreadsheet); 
} 
 
Please get back to us, if you have any other queries. 
 
Regards, 
Arulpriya 


Chris
Replied On January 21, 2020 01:46 PM UTC

Thank you... but is there a way to test to see if the spreadsheet is modified?  I want to create custom prompts, etc.

Chris
Replied On January 21, 2020 01:47 PM UTC

Plus, if I click cancel in the "do you want to save this file" box, it still closes - how would I test that the user clicked Cancel to prevent closing?


Arulpriya Ramalingam [Syncfusion]
Replied On January 22, 2020 10:19 AM UTC

Hi Chris, 
 
Thank you for the update. 
 
Thank you... but is there a way to test to see if the spreadsheet is modified?  I want to create custom prompts, etc. 
The Spreadsheet does not have any public property to check whether the sheet values are updated or changed. This can be achieved by retrieving the property value of IsCellModified through reflection. Please make use od below code and sample. 
 
Example code 
 
protected override void OnClosing(System.ComponentModel.CancelEventArgs e) 
{ 
    PropertyInfo pi = spreadsheet.Workbook.GetType().GetProperty("IsCellModified", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); 
 
    if (pi != null) 
        if (pi.GetValue(spreadsheet.Workbook as WorkbookImpl).ToString() == "True") 
        { 
            //Code to perform your actions. 
        } 
    //To execute the message box to save or cancel the action. 
    this.spreadsheet.Commands.FileClose.Execute(null); 
    if (Form.ActiveForm != null) 
        e.Cancel = true; 
    base.OnClosing(e); 
} 
Plus, if I click cancel in the "do you want to save this file" box, it still closes - how would I test that the user clicked Cancel to prevent closing? 
By default, the Cancel action of FileClose.Execute message box will restrict the form closing and we suspect that the use case might be occurred due to some other customization of executing the Save/Cancel MessageBox. Please refer to the below sample and let us know the code part that are missed in the project to replicate the issue at our end. So that, we could analyze further to provide a better solution at the earliest. 
 
 
 
Regards, 
Arulpriya 


CONFIRMATION

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

Live Chat Icon For mobile
Live Chat Icon