Access Report Items Programmatically
In the examples below we show how to access a report item from within the report and from the invoking application. In the first example let's access a TextBox item from the detail section ItemDataBinding event handler.
Access Report Items from within events
- Select the detail section in the designer, and in the Properties Window, Events tab, find the ItemDataBinding entry and double-click.
-
The event handler passes in "sender" which is a Telerik.Reporting.Processing.DetailSection that represents the section during processing. Thus you can derive:
- A DataObject that represents the underlying data for a record being processed.
- All processing report items.
Use the ElementTreeHelper.GetChildByName() method to locate an item on the report. In the code example below GetChildByName is used to retrieve "textBox1" TextBox.
In the code example below we are referring to a
Processing.TextBox
, notReport1.TextBox
. TheProcessing.TextBox
represents the TextBox during processing and has a different set of properties than theReport1.TextBox
used when defining the report.
The
ElementTreeHelper
may not find the inner Processing report items in ItemDataBinding and NeedDataSource events of the Report item or even in its sections as the Processing tree may not be fully built. In such cases, you may use closer parents or the ItemDataBinding event of the particular report item you try to access.
Access items from the calling application
If we are in the context of a WinForm or WPF Window and we need to access an item from the Report that is shown in a ReportViewer control with an embedded Reporting engine, we can proceed directly following the report hierarchy. We use a report source object of the same type as the report source assigned to the ReportViewer control. Consider the following code:
Access report fields from a Table item
You can reference the report fields from a table item easily using the Report API hierarchy. Consider the following code: