Fast Report Conditional Highlight
I have tried to follow the Condition highlight in the User Manual but I am getting the following error when I type in the condition:
[Data.JanuaryAchieved] >0 though Data.JanuaryTarget is of type System.32.
How can I create multiple conditions. For example if a value is below 4 then Red, else if between 4 and 6 then Orange else Green when above 6.
System.Exception: Text24: Error in highlight condition: [Data.JanuaryAchieved] >0 ---> System.InvalidCastException: Specified cast is not valid.
at FastReport.ReportScript.CalcExpression(String expression, Variant Value)
--- End of inner exception stack trace ---
at FastReport.TextObject.GetData()
at FastReport.BandBase.GetData()
at FastReport.Engine.ReportEngine.PrepareBand(BandBase band, Boolean getData)
at FastReport.Engine.ReportEngine.ShowBandToPreparedPages(BandBase band, Boolean getData)
at FastReport.Engine.ReportEngine.ShowBand(BandBase band, Boolean getData)
at FastReport.Engine.ReportEngine.ShowDataBand(DataBand dataBand, Int32 rowCount)
at FastReport.Engine.ReportEngine.RunDataBand(DataBand dataBand, Int32 rowCount, Boolean keepFirstRow, Boolean keepLastRow)
at FastReport.Engine.ReportEngine.ShowGroupTree(GroupTreeItem root)
at FastReport.Engine.ReportEngine.ShowGroupTree(GroupTreeItem root)
at FastReport.Engine.ReportEngine.RunGroup(GroupHeaderBand groupBand)
at FastReport.Engine.ReportEngine.RunBands(BandCollection bands)
at FastReport.Engine.ReportEngine.RunReportPage(ReportPage page)
at FastReport.Engine.ReportEngine.RunReportPages()
at FastReport.Engine.ReportEngine.RunReportPages(ReportPage page)
at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState, ReportPage page)
at FastReport.Report.Prepare(Boolean append)
at FastReport.Design.ReportTab.Preview()
[Data.JanuaryAchieved] >0 though Data.JanuaryTarget is of type System.32.
How can I create multiple conditions. For example if a value is below 4 then Red, else if between 4 and 6 then Orange else Green when above 6.
System.Exception: Text24: Error in highlight condition: [Data.JanuaryAchieved] >0 ---> System.InvalidCastException: Specified cast is not valid.
at FastReport.ReportScript.CalcExpression(String expression, Variant Value)
--- End of inner exception stack trace ---
at FastReport.TextObject.GetData()
at FastReport.BandBase.GetData()
at FastReport.Engine.ReportEngine.PrepareBand(BandBase band, Boolean getData)
at FastReport.Engine.ReportEngine.ShowBandToPreparedPages(BandBase band, Boolean getData)
at FastReport.Engine.ReportEngine.ShowBand(BandBase band, Boolean getData)
at FastReport.Engine.ReportEngine.ShowDataBand(DataBand dataBand, Int32 rowCount)
at FastReport.Engine.ReportEngine.RunDataBand(DataBand dataBand, Int32 rowCount, Boolean keepFirstRow, Boolean keepLastRow)
at FastReport.Engine.ReportEngine.ShowGroupTree(GroupTreeItem root)
at FastReport.Engine.ReportEngine.ShowGroupTree(GroupTreeItem root)
at FastReport.Engine.ReportEngine.RunGroup(GroupHeaderBand groupBand)
at FastReport.Engine.ReportEngine.RunBands(BandCollection bands)
at FastReport.Engine.ReportEngine.RunReportPage(ReportPage page)
at FastReport.Engine.ReportEngine.RunReportPages()
at FastReport.Engine.ReportEngine.RunReportPages(ReportPage page)
at FastReport.Engine.ReportEngine.Run(Boolean runDialogs, Boolean append, Boolean resetDataState, ReportPage page)
at FastReport.Report.Prepare(Boolean append)
at FastReport.Design.ReportTab.Preview()
This discussion has been closed.
Comments
Hello!
Why does [Data.JanuaryAchieved] > 0 throw an InvalidCastException? In .NET/C#, this happens when a table field is returned as DBNull (or has a DataType of String), which prevents the direct > 0 operator from casting the value to an int. A reliable way to write the condition: !IsNull(“Data.JanuaryAchieved”) && ToInt32([Data.JanuaryAchieved]) > 0.
How to set three color ranges without a script (< 4 red, 4..6 orange, > 6 green): In the designer, select the TextObject -> click the Highlight button (or add 3 elements to textObject.Highlight in the code) with the following conditions:
Condition 1: ToInt32([Data.Val]) < 4 -> Fill = new SolidFill(Color.Red), ApplyFill = true
Condition 2: ToInt32([Data.Val]) >= 4 && ToInt32([Data.Val]) <= 6 -> Fill = new SolidFill(Color.Orange), ApplyFill = true
Condition 3: ToInt32([Data.Val]) > 6 -> Fill = new SolidFill(Color.Green), ApplyFill = true