Hi,
I'm using WorkbookDirtied-event to see if there are any changes made to a workbook. In my application I have certain cells that I have to update after loading the workbook. After loading and updating, I begin to listen WorkbookDirtied-event. My problem is that the event triggers right away (sometimes multiple times), even if all changes were made before attaching a listener for the event.
So how could I do my initialization without causing WorkbookDirtied to be triggered?
Hello Tg,
Thank you for your post.
The reason that this WorkbookDirtied event is firing at "strange" times is because the event is essentially the result of an asynchronous callback based upon a flag that is set when something about the workbook changes. Internally to the XamSpreadsheet, we are listening for a change notification from the workbook. This change notification sets a flag and starts an asynchronous callback which raises the WorkbookDirtied event asynchronously, and so the trigger of this event that you are seeing is likely a timing issue between your changes happening and the WorkbookDirtied event being handled.
The reason that we do the asynchronous callback for this event is so that you will only ever actually have a single event for a bunch of changes, and it will prevent the event from firing while the user may be changing multiple things about the workbook.
The way to prevent this is to simply make the changes that you need to make prior to actually setting the XamSpreadsheet's Workbook property. You can make these changes by viewing the corresponding Worksheet(s) that will exist in your Excel workbook's Worksheets collection. This will prevent the WorkbookDirtied event from being triggered because at this point, the XamSpreadsheet will not know about your workbook, and so it won't get notified of your changes. This will prevent the flag from being set, which will prevent the callback that asynchronously fires the WorkbookDirtied event.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
I can understand why WorkbookDirtied event is handled asynchronously.But what if I'd like to suspend it somehow, after workbook has been assigned to spreadsheet control?I'd really like it might work like:
spreadsheet.EventManager.SetEnabled(UltraSpreadsheetEventIds.WorkbookDirtied, false); //some operation spreadsheet.EventManager.SetEnabled(UltraSpreadsheetEventIds.WorkbookDirtied, true);
But it does not.
Is there other way to achieve this goal without detaching workbook from spreadsheet control?