|
I have a problem with Excel Cut and Paste in my VSTO application.
I have implemented a solution for a financial system where I have model component modelling a complex financial system, holding all the financial values, relationships etc., and an Excel interface to the this model displaying the figures in tabular form.
I have layer between the Excel interface and my Model connecting the two, which is implemented using VSTO 2005, i.e.
Excel 2003 Interface
------
VSTO 2005 Layer
------
Financial System Model, C#, .Net
In the connecting VSTO layer I have registered an event handler with the Microsoft.Office.Interop.Excel.Worksheet.Change event so that I can propagate the updates to my model, which causes the financial model to recalculate and then update the Excel with it's updated figures.
I have hit a problem with cut and paste as this raises two change events, first for the cut, which supplies the cut range, and second for the paste, which supplies the paste range. Each event range parameter will allow access to the range values as currently displayed on the screen. My problem is that the first cut event causes my model to update the screen, and replaces the paste range values with the values currently in the model.
A better example of what is going wrong is as follows:
- I have four cells with the values, Cell 1 = "1", Cell 2 = "2", Cell 3 = "empty", Cell 4 = "empty".
- I select Cell 1 and ,Cell 2, and cut.
- I select Cell 3 and ,Cell 4 and paste
- The Cut causes Microsoft.Office.Interop.Excel.Worksheet.Change event to be raised with range containing Cell 1 = "empty" and ,Cell 2 = "empty", and update is propagated to the model.
- The model updates and updates Excel so that Cell 1 = "empty", Cell 2 = "empty", Cell 3 = "empty", Cell 4 = "empty"
- The Paste event causes Microsoft.Office.Interop.Excel.Worksheet.Change event to be raised with range containing Cell 3 = "empty" and ,Cell 4 = "empty", and update is propagated to the model.
So instead of the expect Cell 1 = "empty", Cell 2 = "empty", Cell 3 = "1", Cell 4 = "2", I get Cell 1 = "empty", Cell 2 = "empty", Cell 3 = "empty", Cell 4 = "empty"
I have found no way of reliably identifying that the Cut state Microsoft.Office.Interop.Excel.Worksheet.Change event raised.
I have tried checking, Microsoft.Office.Interop.Excel.Application.CutCopyMode == Microsoft.Office.Interop.Excel.XlCutCopyMode.xlCut, but by attaching to the Microsoft.Office.Interop.Excel.Application.SelectionChange event I have observed that this only true up until the paste occurs and once my change event handler has been reached this has been set back to false.
Can anyone suggest how I can reliably identify the first change Event as being due to a Cut, as I think this would allow me code for the cut and paste scenario.
Or can anyone suggest some other part VSTO library that would enable me to hook into Excel Cut and Paste. |