Ticket T108946
Visible to All Users

DevExpress.XtraReports.UI.XRLabel.Summary.GetResult inside .BeforePrint event always equals zero

created 11 years ago (modified 11 years ago)

I am programming a desktop .NET 3.5 application with a SQL server backend. I am using DevExpess 12.2.5.0.
I have been trying to apply a type of conditional formatting in the GroupHeaderBand section of my report.

My report uses a custom object as its datasource. I have 7 levels of grouping. Each GroupHeaderBand has labels that display totals for corresponding column data , ie: let's say I have data on potato useage costs per country, state, city, etc. the top level would have the total cost for that country. Each level would correspond to that heirachy and have a total useage cost.

I am using the BeforePrint event for that label to display the data.

Visual Basic
Private Sub XrLabel104_BeforePrint(sender As Object, e As System.Drawing.Printing.PrintEventArgs) Handles XrLabel104.BeforePrint Dim currentValue As Decimal = Convert.ToDecimal(CType(sender, DevExpress.XtraReports.UI.XRLabel).Summary.GetResult) If currentValue = 0 Then CType(sender, DevExpress.XtraReports.UI.XRLabel).XlsxFormatString = "$#,###,###,##0;[Red]($#,###,###,##0)" Else Dim centsValue As String = Strings.Right(Math.Round(currentValue, 2).ToString(), 2) If centsValue = "00" Then CType(sender, DevExpress.XtraReports.UI.XRLabel).XlsxFormatString = "$#,###,###,##0;[Red]($#,###,###,##0)" CType(sender, DevExpress.XtraReports.UI.XRLabel).Summary.FormatString = "{0:$0}" ElseIf Strings.Right(centsValue, 1) = "0" Then CType(sender, DevExpress.XtraReports.UI.XRLabel).XlsxFormatString = "$#,###,###,##0.#;[Red]($#,###,###,##0.#)" CType(sender, DevExpress.XtraReports.UI.XRLabel).Summary.FormatString = "{0:c1}" Else CType(sender, DevExpress.XtraReports.UI.XRLabel).XlsxFormatString = "$#,###,###,##0.##;[Red]($#,###,###,##0.##)" CType(sender, DevExpress.XtraReports.UI.XRLabel).Summary.FormatString = "{0:$0.00}" End If End If End Sub

On line two of the code, the Summary.GetResult always comes back as zero. However, when the report is done exporting to excel, the values are correct. I assigned the value to be processed (currentValue) to be the output from the function Summary.GetResult. It always returns zero.

I also tried to use the .SummaryCalculated event.

Visual Basic
Private Sub XrLabel104_SummaryCalculated(sender As Object, e As DevExpress.XtraReports.UI.TextFormatEventArgs) Handles XrLabel104.SummaryCalculated Try Dim currentValue As Decimal = e.Value If currentValue = 0 Then CType(sender, DevExpress.XtraReports.UI.XRLabel).XlsxFormatString = "$#,###,###,##0;[Red]($#,###,###,##0)" CType(sender, DevExpress.XtraReports.UI.XRLabel).Summary.FormatString = "{0:$0}" Else Dim centsValue As String = Strings.Right(Math.Round(currentValue, 2).ToString(), 2) If centsValue = "00" Then CType(sender, DevExpress.XtraReports.UI.XRLabel).XlsxFormatString = "$#,###,###,##0;[Red]($#,###,###,##0)" CType(sender, DevExpress.XtraReports.UI.XRLabel).Summary.FormatString = "{0:$0}" ElseIf Strings.Right(centsValue, 1) = "0" Then CType(sender, DevExpress.XtraReports.UI.XRLabel).XlsxFormatString = "$#,###,###,##0.#;[Red]($#,###,###,##0.#)" CType(sender, DevExpress.XtraReports.UI.XRLabel).Summary.FormatString = "{0:c1}" Else CType(sender, DevExpress.XtraReports.UI.XRLabel).XlsxFormatString = "$#,###,###,##0.##;[Red]($#,###,###,##0.##)" CType(sender, DevExpress.XtraReports.UI.XRLabel).Summary.FormatString = "{0:$0.00}" End If End If Catch ex As Exception End Try End Sub

This stepped through this code and it actually has relevent data and processes the data correctly. However, when we get the excel spreadsheet, the formatting defaults to the Summary.FormatString default. (always "{0:$0.00}"

I have used each event separately or together, but the outcome is the same.

Please advise.

Answers approved by DevExpress Support

created 11 years ago (modified 5 years ago)

Hi Ruben,

This is expected behavior. The BeforePrint event handler is called too early and the summary value is not yet calculated. That's why the summary value is not accessible in this event handler.
And to the contrary, the SummaryCalculated event handler is called too late, so you cannot change the control properties.

To accomplish your task, I suggest you calculate your summary value manually. In this case, you will be able to get the summary value in your BeforePrint event handler. Please refer to the Calculating a Custom Summary help topic for more information regarding the manual summary calculation approach.

    Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

    Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.