Hello!
I have a grid that is filled with different types of products. One column in this grid is a cost price column.
I have added summaries to the grid and my idea was to get the total price of the products through the summary value that is based on the cost price column.
Another option could be to calculate the total price based on the datasource that populates the grid, but since I have enabled editing of the grid, it feels a bit wrong.
At the moment, I am setting the cost price in the summaryvaluechanged event, which then calculates the sales price. So we have:
summaryvaluechanged->costprice->salesprice.
The summaryValueChanged event fires many times, since I have groupbyrows. However, it works even if it is fired many times.
So far so good...
It is quite common that the users wants to override the sales price and create some sort of rounded value that is presented to the customer.
The problem that I get is when I export the data from the grid to excel. The grid seems to be re-generated when it is exported, so the summaryvaluechanged event fires a new round. This means that the cost price is calculated again, and so is the sales price. It gets overwritten which is not good. I ahve tried to lock down the event before i export the grid and to open it up again after it is exported. However, since the grid works async, I turn on the event before the summaryvaluechanged event has finished firing. So the value is overwritten...
I hope that someone can understand what I am trying to explain. I am not sure if I understand it myself ;-)
Any ideas?
/Henrik
Hello Henrik,
Thank you for your feedback
I am glad to hear that you have resolved your issue. Please let me know if you need any further assistance.
Yepp, you are correct. When the summaryValueChanged event fires, it starts some calculations. The grid contains cost prices, and the sales team wants sales prices.
So when the cost price changes, it recalculates the sales price. The problem is that when the cost price is something 999, the sales persons rounds this off to 1000.
When the excel export is called, it then makes the summaryValueChanged event to fire, which in the end will set the sales price back to 999. I think you get the Picture ;-)
I am not sure if the suspend/resume approach really worked. I got a feeling that it just paused these recalculations until I called resume. However, I have combined
some lines of code that did the trick. I saved the last calculated cost price , so when it is recalculated (when the export is called), I can compare to see if it a new value or just the same. If it is different, I will recalculate.
Thansk for all help Milko!
If I understand you correctly you are recalculating some values in SummaryValueChanged event. When you export the grid you need this values to remain the same, e.g. CalcManager should not recalculate them. If this is what you are looking for please consider using SuspendCalc and ResumeCalc methods of the UltraCalcManager. More about these methods you may find by following the next link http://help.infragistics.com/Help/Doc/WinForms/2015.1/CLR4.0/HTML/Infragistics4.Win.UltraWinCalcManager.v15.1~Infragistics.Win.UltraWinCalcManager.UltraCalcManager~SuspendCalc.html
As you are exporting the grid asynchronously you may call SuspendCalc on button click, before you start the export and then call the ResumeCalc in ExportEnded event of the UltraGridExcelExporter.
However in the sample you have sent me there are no any calculations in SummaryValueChanged event. If you can send me a modified sample showing exactly what you are trying to achieve it will allow me to investigate this further and to send you a possible solution.
Looking forward to your feedback.
Thanks Milko!
I guess this means that your solution doesn't work in all cases?
Currently, I am closing down the summaryValueChangedEvent before I export the cells, and opening it up again when the export is ready. It worksalright, but since the grid works async, it doesn't feel perfect if you know what I mean?
However, if you don't have any other ideas, I think I stick with that...
Thanks again!
Thank you for the sample provided.
When you start the export the grid layout recalculates all the formulas. This recalculation fires several times SummaryValueChanged event. When the recalculation is finished the exporter creates a clone of the grid layout. During this process SummaryValueChanged is called again this time on ExportLayout. This is why in your sample SummaryValueChanged is called several times from the grid layout and then some more times by the export layout.
In my sample summary values are not calculated via UltraCalcManager and this is why SummaryValueChanged is called less times than in your code.
Please let me know if you need any further assistance.