Example 1. Changing object's appearance

Top  Previous  Next

In this example we will show how to change the color of the text depending on the value printed in the object. We will be using:

 

the BeforePrint event;
reference to the data column from script.

 

Create a simple report having the following appearance:

 

scriptEvents1

 

Select the object, which prints the "UnitPrice" column, and create a BeforePrint event handler:

 

private void Text2_BeforePrint(object sender, EventArgs e)

{

  if (((Decimal)Report.GetColumnValue("Products.UnitPrice")) > 20)

    Text2.TextColor = Color.Red;

}

 

In order to insert the "Products.UnitPrice" data column into the script, drag it from the "Data" window. During this, the following string will be added in the script:

 

((Decimal)Report.GetColumnValue("Products.UnitPrice"))

 

If we run the report, we will see that all the products, having the price > 20, are highlighted in red:

 

scriptExample1

 

The same effect can be achieved with the help of the conditional highlighting (you can read more about this in the "Conditional highlighting" section of the "Report creation" chapter).