Inherited Reports with Standalone Report Designer

3 posts, 0 answers
  1. Richard
    Richard avatar
    35 posts
    Member since:
    Jun 2009

    Posted 17 Apr Link to this post

    I am trying to move a project from the Visual Studio Report Designer to the standalone Report Designer. Most of my reports are inherited from Telerik.Reporting.Report, so I want to be able to keep the custom code in each class, but to load the report from a TRDP file.

    The class definition and constructor of my classes looks something like:

    public partial class MyReport : Telerik.Reporting.Report
    {
        public MyReport()
        {
            InitializeComponent();
            // ... class specific code ...
        }
    }

     

    I would like to be able to initialize the report with a trdp file to look something like the following:

    public class MyReport : Telerik.Reporting.Report
    {
        public MyReport()
        {
            LoadReport("c:\SomeFolder\MyReport.tdrp");
            // or
            LoadReport(Resources.MyReport);
            // ... class specific code ...
        }
    }

     

    Any ideas or am I completely doing it wrong?

     

     

  2. Todor
    Admin
    Todor avatar
    175 posts

    Posted 20 Apr Link to this post

    Hi Richard,

    What you would like to achieve is possible, but might require extra efforts based on what is the class specific code supposed to do.

    If the code will change the report definition, i.e. add/modify report items, you may find the approach more requiring than storing the report definitions in classes.

    The problem in this case is with accessing the report items in report definition.
    If the report definition is a class that inherits Telerik.Reporting.Report, the report items/components could be accessed within the class as this.ReportItem. For example to set the DataSource of 'list1' the following code can be used:

    ObjectDataSource objectDataSource1 = new ObjectDataSource();
    objectDataSource1.DataSource = typeof(Cars);
    objectDataSource1.Name = "objectDataSource1";
     
    this.list1.DataSource = objectDataSource1;

    However, if the report is defined in a TRDP file (compressed XML file), upon unpacking it with the ReportPackager UnpackageDocument() method it can be cast to Telerik.Reporting.Report, since there would be no class for the specific report definition. Therefore, only public properties/method defined in the Telerik.Reporting.Report class would be accessible. The report items that are specific for each report in this case can be accessed with their names and the names of their container(s). For the above example the code could look like:

    ObjectDataSource objectDataSource1 = new ObjectDataSource();
    objectDataSource1.DataSource = typeof(Cars);
    objectDataSource1.Name = "objectDataSource1";
     
    DetailSection detail = (DetailSection)this.MyUnpackedReport.Items["detail"];
    List list1 = (List)detail.Items["list1"];
    list1.DataSource = objectDataSource1;

    If the class specific code does not use the items defined in the InitializeComponent() method, the approach by using TRDP reports might be as effective as using report definition class.

    Note also that when using Report Viewers to display reports it would be necessary to wrap them in InstanceReportSource. There would be no specific report class to use with TypeReportSource, and the the TRDP file would not contain all the necessary information for the report to be used with UriReportSource.

    Regards,
    Todor
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Richard
    Richard avatar
    35 posts
    Member since:
    Jun 2009

    Posted 20 Apr in reply to Todor Link to this post

    Todor,

    Thanks for the very complete response. 

     

Back to Top