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 BasicPrivate 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 BasicPrivate 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.