New to Telerik Reporting? Download free 30-day trial

Changes on Items in Report Events Are Not Applied

Environment

Product Progress® Telerik® Reporting

Description

In Telerik Reporting versions prior to R3 2016, all changes in events were accepted, even these applied on items' definitions. When items' definitions were modified in the event handlers, changes were applied on all consecutive processing elements with the expected result.

Modifying report in events prior to R3 2016:

void report_NeedDataSource(object sender, EventArgs e)
{
    this.DataSource = GetReportData();
    this.table.DataSource = GetTableData();
}

With R3 2016, we applied an optimization change in the report rendering algorithm and now each definition item property values are read and cached once the report rendering starts.

If you are working with item definitions in events, they may remain unchanged. For more details, check the updated Understanding Events help article.

Solution

  • Modifying Report item in events after R3 2016:

    void report_NeedDataSource(object sender, EventArgs e)
    {
        Telerik.Reporting.Processing.Report processingReport = (Telerik.Reporting.Processing.Report)sender;
        processingReport.DataSource = GetReportData();
    }
    

    In the report NeedDataSource and ItemDataBinding events, the processing instances of the other report items are not created yet. Hence, it is not possible to modify other items in these Report events.

  • Modifying other items in events after R3 2016:

    void table_NeedDataSource(object sender, EventArgs e)
    {
        Telerik.Reporting.Processing.Table processingTable = (Telerik.Reporting.Processing.Table)sender;
        processingTable.DataSource = GetTableData();
    }
    

In all versions of Telerik Reporting, changes in events are possible if they are applied on the processing elements, not the items' definitions (report elements accessible through this. in C# or Me. in VB.NET). The valid approaches are illustrated in Accessing Report Items Programmatically.

The recommended approach is to use the expression engine and to avoid custom code in events:

  1. Conditional Formatting to control styles via expressions;
  2. Bindings to set properties of items via expressions;
  3. User functions to set properties of items, when the built-in functions are not sufficient.

The usage of the expression engine assures items will be modified at the right moment.

Notes

If you have many legacy reports and changing the code in events in all of them is not an option, you could give up on the property resolution optimization and turn it off. To do so, apply the following settings in Telerik.Reporting configuration section in application configuration file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <!-- section handler ok; 1 extension  -->
    <configSections>
        <section
            name="Telerik.Reporting"
            type="Telerik.Reporting.Configuration.ReportingConfigurationSection, Telerik.Reporting.Configuration, Culture=neutral, PublicKeyToken=a9d7983dfcc261be"
            allowLocation="true"
            allowDefinition="Everywhere"/>
    </configSections>
    //...
    <Telerik.Reporting>
        <processing cacheDefinitionProperties="false" />
    </Telerik.Reporting>
</configuration>

See Also

In this article