Conditional highlighting

Top  Previous  Next

There is a possibility to change the "Text" object's appearance depending on the given conditions. For example, an object can be highlighted with red color if it has a negative value. This feature is called "conditional highlighting". To set up it, select the "Text" object and click the btn24 button on the "Text" toolbar.You will see the following dialog window:

 

highlight

 

 

It is possible to define one or several conditions and set up the style for every condition. Style can contain one or several settings:

 

frame;
fill;
font;
object's visibility.

 

You can indicate, which settings need to be changed when the condition is met. For this, check the needed setting using the checkbox.

 

In order to create a new condition, click the "Add" button. You will see an expression editor. Here, it is possible to write any expression which returns a boolean result. In many cases you will use the "Value" variable, which contains the currently printing value.

 

Let us look at the following example: we have a "Text" object, in which we print the amount of products in stock:

 

[Products."UnitsInStock"]

 

We want to paint the object red, if the amount of products = 0. For this, we create the following condition:

 

Value = 0

 

Attention: if you have selected C++Script as a script language (see more details in the "Script" chapter), you should write the condition using C++Script:

 

Value == 0

 

In the given case, we used the "Value" variable, which has got a printed value. If there are several expressions in an object, then this variable will have the value of the last expression. Instead of "Value", you can use a data column:

 

<Products."UnitsInStock"> = 0

 

Configure the style for the given condition in such a way that only fill can be used, and choose the red color:

 

highlightRed

 

When printing an object which has a zero value, it will be red. Let us make our example more complex, we will add another condition. If the units in stock is less than 10, it must be printed yellow. To do this, open the condition editor and click the "Add" button. The second condition will be like this:

 

Value < 10

 

In case where several conditions have been indicated, FastReport checks all the conditions, starting from the first one. If a certain condition is met, FastReport applies its style settings to the object, and the process stops. It is important to put the conditions in a correct order. The order which we have seen in this example is correct:

 

1. Value = 0

2. Value < 10

 

If we swap conditions, then the highlighting will work wrongly.

 

1. Value < 10

2. Value = 0

In the given case, the "Value = 0" will not be executed, because when the value is zero, then the first condition will be met. In order to change the order of the conditions, use the btn208 and btn209 buttons.