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
Thanks!
I tried your code and it works as you mentioned.
When you export, the event is called once with the correct value for isexportlayout. When I try it onmy grid, the event is fired many times and one had a the right value for isexportlayoyt(true), but the rest of the calls were with the value of false.
Really strange...
I found some differences in my code compared to yours, so I updated yours. Now it works as mine.
Please have a look at it.
The SummaryEvent is fired many times and the value of isexportlayour differs...
Hello Henrik,
Thank you for your feedback.
I followed the steps you suggested and was unable to reproduce the behavior you're describing. In my sample the grid has three numeric columns – Quantity, Price and Total. Initially Total column value is equal to the product of the Quantity and Price. I have add summary to the Total column. If the user changes the value of the Total in SummaryValueChanged event handler a new value for the Price column is calculated. With all these settings when I change some Totals and export the grid all the numbers in the exported Excel worksheet are correct. During the export several times IsExportLayout property returns true (please check the Output window after Export to Excel button was clicked).
I have attached the sample project I used to test this. Please test this project on your PC; whether or not it works correctly may help indicate the nature of this issue.
If this sample project is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.
Please let me know if I can provide 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.
The isExportLayout is false all the time, even when the grid is exported.
i use the ultragridexcelexporter, and the method export.
Can I do something wrong?
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.