//Event subscription.
this.FormClosing += Form1_FormClosing;
//Event customization
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
spreadsheet.Commands.FileClose.Execute(this.spreadsheet);
} |
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.
|