Search Results for

    Show / Hide Table of Contents

    Example 1. Changing object's appearance

    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:

    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:

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

    Back to top © 1998-2025 Copyright Fast Reports Inc.