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 posting in our forum.Without providing me a sample solution I cannot be quite sure what exactly you are trying to achieve. However from your post I understand that you have an issue while exporting the grid to Excel. Please note that when the export starts the exporter creates a copy of the Layout. So one possible solution to your issue could be if you check in SuumaryValueChanged event handler if the event was fired by the exported layout. You can use code like this:private void ultraGrid1_SummaryValueChanged(object sender, SummaryValueChangedEventArgs e){ if (e.SummaryValue.ParentRows.Band.Layout.IsExportLayout) { return; }}Please let me know if this solves your issue. If note please try to isolate this behavior in small sample solution and send it to me in order to be able to research a possible solution for you. Looking forward to your reply.
thanks, that could be really useful. by the way, is there some sort of way finding out when the top level summary value changed event is fired? that could be useful as well. then i can handle that one only...
Hello Henrik,
Thank you for your feedback.
If I understand you correctly you need to check if the SummaryValueChanged event was fired when a summary value of the top level band was changed. In order to achieve this you may check if the parent band of the affected summary value’s band is null. If so this is the top level band. You can use code like this:
if (e.SummaryValue.ParentRows.Band.ParentBand == null)
{
// TODO: implement your logic here
}
Please let me know if you need any further assistance.
When it comes to finding out which is the top level SummaryValue, I used the code below. It seems to work:
If e.SummaryValue.ParentRows.ParentRow Is Nothing Then
...
End If
So we can drop that question and focus on the export issue.
Let me know if you get any ideas of that.
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.