Search Results for

    Show / Hide Table of Contents

    Example 2. Highlighting even rows of the band

    In this example we will show how to change the fill color of the "Data" band's even rows. We will be using:

    • BeforePrint band event;
    • reference to the Row# system variable from the script.

    Create a simple report having the following appearance:

    Create a BeforePrint event handler for the band:

    private void Data1_BeforePrint(object sender, EventArgs e)
    {
      if (((Int32)Report.GetVariableValue("Row#")) % 2 == 0)
        Data1.FillColor = Color.Gainsboro;
    }
    

    The Row# system variable returns the number of the row of the printed band. In order to insert into the script a reference to the variable, drag it from the "Data" window. During this, in the script a string will be inserted:

    ((Int32)Report.GetVariableValue("Row#"))

    If we run the report, we will see that even rows will be highlighted in light-gray color:

    The same effect can be achieved with the help of the EvenStyle property of the "Data" band. You can read more about this in the "Highlight odd/even data rows" section of the "Report creation" chapter.

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