Using Conditional Formatting
Using conditional formatting, you can apply formatting based on the outcome of pre-set conditions (set at design time) and checked at run time. Conditional formatting is applied at runtime on a field or a label control as shown in the examples below:
Display the record in Bold if result of a student is ‘Fail’.
Display the figure in red and in braces if the profit figure is ‘Negative’.
Display the sales value in light blue background if the sales target is met, in yellow if the target is missed by up to 25 %, and in red if it is missed by more than 25%.
Before applying conditional formatting, you should set the required conditions and required formats.
To apply formats to controls
Conditional formats are applied to a control or a label using Conditional Formatting screen. Before opening the Conditional Formatting screen, select the control on which the format is to be applied.
To access Conditional Formatting screen,
On the Desktop Studio screen, click button from the toolbar.OR
On the Desktop Studio screen, from Format menu, click Conditional Formatting. The Conditional Formatting screen appears.
Figure 8: Conditional Formatting screen
You can perform the following actions:
Action | Comments |
Add | To create/add a new conditional format |
Delete | To delete the selected conditional format |
Import | To import the pre-existing conditional formatting |
Export | To export the newly created conditional formatting |
Conditions | To open Conditions screen to create a new condition |
Formats | To open Styles screen to create a new style/format |
OK | Save all the changes made to the condition |
Cancel | Close screen without making changes to the report |
To apply/create conditional formatting
On the Conditional Formatting screen,
Click Add The Conditional Formatting screen appears.
Select a condition from On Condition drop-down list, for which you want to apply a format.
Select the format from Apply Style drop-down list that you want to apply for the selected condition of the control.
Note: When you apply styles to a control from style drop down box, respective properties of the control will not automatically change (in property pane).
After applying formatting preferences for all the conditions, click OK button to save the created conditional formatting. The newly designed conditional formatting appears in the list on the Conditions Formatting.
Conditional Formatting through Scripting
You can achieve conditional formatting through Scripting too.
You can format a displayed row value if the values of that row satisfy a given condition. For example, if you need to compare the database field (say ‘dbfield’) with a field in the previous row, and encircle it in red if it is different, add a text box (say ‘text box’) in the report header and set its visible property (from the Properties list) as ‘False’.
Set its text property (from the Properties list) to any arbitrary value (say ‘-999’) that can never be attained by the field to be compared with.
Now, add a shape (say “shape1”) around the ‘dbfield’ and set its color and shape to a red ellipse. The same can be achieved using the Script Editor as follows:
On the Desktop Studio screen, from Tools menu, click Scripting.
Select object as Detail.
Select event as OnFormat.
Enter the following JavaScript:
Object: Detail Event: OnFormat
Code:
function OnFormat()
{
if ( ( rpt.Section(“ReportHeader”).Controls(“txtBox”).text != “_99999” ) &&
( rpt.Fields(“dbValue”).value != rpt.Sections(“PageHeader”).Controls(“txtBox”).text ) )
{
rpt.Sections(“Detail”).Controls(“Shape1”).visible = true ;
}
else
{
rpt.Sections(“Detail”).Controls(“Shape1”).visible = false ;
}
rpt.Sections(“PageHeader”).Controls(“txtBox”).text = rpt.Fields(“dbField”).value;
}
Related content
Copyright Kyvos, Inc. All rights reserved.