Hi,
We are implementing Dirty flag detection into XamSpreashead control but we face problems to detect early change/delete/add actions. We attached to WorksheetDirtied event but this event is raised even when scroll is changed thus does not fit to our needs.
Additionally, checking received argument event SpreadsheetWorkbookDirtiedEventArgs does not bring any value either since has no additional information about cell (old and new value, added or deleted or changed, nor address of cell itself).
Currently we need to serialize and deserialize all workbook to achieve this and this very expensive operation since we might have very big worksheets (50+ Mb).
How to detect when cell is starting to change?
What value has changed to and what was before?
What was the action of the cell: delete or add?
What was the address of the Cell and in which worksheet?
Thanks in advance,
Tomas
Hi Tomas,
Thank you for the sample application you have provided.
From your initial questions my impression was that you are interested in the specific cell changes, i.e. address of changed cell, its old and new value, what was the exact action, etc. So, that was what the proposed sample was focusing on.
In the case that your requirement is to determine whether any change that modifies the worksheet was performed, my suggestion is to handle the spreadsheet’s CommandExecuted event and check the SpreadsheetCommandType of its e.Command argument:
private void spreadSheet_CommandExecuted(object sender, SpreadsheetCommandExecutedEventArgs e) { SpreadsheetCommandType command = e.Command; switch(command) { case SpreadsheetCommandType.Cut: SaveWorkbookDirtied.IsEnabled = true; break; case SpreadsheetCommandType.Paste: SaveWorkbookDirtied.IsEnabled = true; break; //….. } }
You can find a full list of the Spreadsheet commands here and add a case for any command that makes sense in your scenario. I have modified your sample application to demonstrate this approach with some additional commands that are triggered on common spreadsheet changes. The OnEditModeExiting event is still handled to check for manual cell changes.
You can find the sample attached below. Please, test it on your side and let me know how it behaves.
Sincerely,
Bozhidara Pachilova
Associate Software Developer
3782.SpreadsheetMinimalPrototype-modified.zip
Problems still occurring with used approach:
These answers are of course based on our limited knowledge with the events. If we missed a crucial point you are very welcome to point it out to us, we would be happy if there is already an existing and simple solution for our problem in the product.
I attached a minimal prototype with which you can verify our problems 1106.SpreadsheetMinimalPrototype.zip. If you start scrolling the WorkbookDirtied-Save button gets enabled (though it should not) and if you paste a value the EditModeExiting-Save button does not get enabled (though it should).
Same answer posted to Infragistics idea: https://es.infragistics.com/community/ideas/i/ultimate-ui-for-wpf/xamlspreadsheet-events-on-user-cell-value-cell-value-range-changed
best regards,
Thanks for response. It works in most cases but it does not cover all possible combinations. So will have to create an idea then.
Hello,
I have been looking into your question and after an investigation, I determined that there is no such event provided out of the box. I have implemented some custom logic to achieve similar behavior and get information like new value, old value, current worksheet, address, etc. of the edited cell.
I defined a struct called ChangedCell which stores information about the cell as per your requirements. In order to retrieve the currently active cell, on which editing or deletion may be executed I handle the ActiveCellChanged event of the XamSpreadsheet. From there the initial cell info, such as a worksheet, row, column, address and current value, could be get. If the cell was edited, its new value can be retrieved from the EditModeExiting event of the XamSpreadsheet. In order to detect if the cell was deleted, the KeyUp event of the XamSpreadsheet can be handled. If there is an active cell selected and the pressed key is "Delete", we know the cell was deleted.
I have attached a sample application, that uses the approach below.
Please keep in mind that the suggested approach is a workaround and in case it is not an accurate demonstration of what you are trying to achieve, my suggestion is submitting a new product idea. You can suggest new product ideas for future versions (or vote for existing ones) at <http://ideas.infragistics.com >.
There are many benefits to submitting a product idea:
- Direct communication with our product management team regarding your product idea.
- Notifications whenever new information regarding your idea becomes available.
- Ability to vote on your favorite product ideas to let us know which ones are the most important to you. You will have ten votes for this and can change which ideas you are voting for at any time.
- Allow you to shape the future of our products by requesting new controls and products altogether.
- You and other developers can discuss existing product ideas with members of our Product Management team.
If you require any further assistance on the matter, please let me know.
Sincerely,Bozhidara PachilovaAssociate Software Developer
4747.XSDetectChangedCells.zip