This is a migrated thread and some comments may be shown as answers.

Getting items from a sub-report within a sub-report

1 Answer 88 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Von
Top achievements
Rank 1
Von asked on 19 Nov 2011, 02:50 AM
Hi,

I have report that contains a sub-report. The sub-report itself contains a sub-report. My goal is to get that sub-report within the sub-report of my main report so I can populate it's data. So I have the following:

* master report
     * a sub-report inside the master report
         * a sub-report inside the sub-report  mentioned above

Take note that I am populating data using an objectsource. Now, I have the following code:
var mainReport = new TheReport();
 
// this works fine
var detail = ((mainReport.Items[0] as Telerik.Reporting.DetailSection)
                    .Items["subReport"] as Telerik.Reporting.SubReport);
 
// this one does not work
var innerDetail = ((detail.Items[0] as Telerik.Reporting.DetailSection)
                    .Items["innerSubReport"] as Telerik.Reporting.SubReport);

"detail.Items" does not contain any element. I can also confirm that just by looking into the mainReport.Items collection. Using VS' watch window I manually navigate through the mainReport.Items collection, located the details section and investigated its own Items collection. The items collection is really empty for the details section. 

How can I get the inner sub-report so I can manipulate it?
    

1 Answer, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 21 Nov 2011, 05:45 PM
Hello Von,

See the code snippet below for more info:

var detail = ((mainReport.Items[0] as Telerik.Reporting.DetailSection)
                    .Items["subReport"] as Telerik.Reporting.SubReport);
//By doing this you get the subReport container item, not the report it represents
//In order to get the report itself you should
var detailReportSource = detail.ReportSource;

//There is another option in the subReport ( the one that is in the main report)
//you can expose public property that gets the most inner report
//and then you access it directly
public partial class Report2 : Telerik.Reporting.Report
    {
        public Telerik.Reporting.Report subReport3
           {
              
get return this.report31;}
           }
 
        public Report2()
        {
            InitializeComponent();
        ...
        }
    }
 
//and then in the main report you can access it like this:
var mostInnerReport = this.report21.subReport3;

Although by doing that you will only have access to the definition of the inner reports, not the processing items. If you want to change the data it displays at runtime you should consider doing it in some other way (Report parameters, different report logic). 



Best wishes,
Elian
the Telerik team

Q2’11 SP1 of Telerik Reporting is available for download (see what's new). Get it today.

Tags
General Discussions
Asked by
Von
Top achievements
Rank 1
Answers by
Elian
Telerik team
Share this question
or