Hi
I have been looking around for a sample and found many links broken or for which the code is not working anymore (dating back from 2007-2010!)
- I have a dataset containing multiple tables already in memory.
- This dataset is created by the application (not directly coming from the database).
- I have created a typed dataset from it to be able to create a report (including sub-reports for additional tables of my dataset)
- How can I programmatically pass the tables[1] to the sub-report (call it srHoldings)?
- I don't want to re-query the database, I want to use the dataset already in memory.
1 Answer, 1 is accepted
Hello Eric,
The SubReport item itself does not have a DataSource property, instead, the SubReport.ReportSource report should have its DataSource edited.
For example, if the SubReport.ReportSource is some URI to a report file, then it will be of type UriReportSource, and you can use its Uri property to get the report URI, unpackage it and then edit it.
It's not the easiest operation to edit a SubReport report's data source as this explanation suggests so I would suggest an alternative approach.
The alternative approach is to put the SubReport item inside a list item(in the main report) where the report, which will be used as a subreport, can have a binding on its DataSource that takes the data object of the parent item, in this case, the list. This way, instead of going through this whole operation to update the subreport report's DataSource, you can just update the list.DataSource and it will immediately take effect in the SubReport.
See the How to bind Sub Report to Main Report's Data article for an example of this approach.
Regards,
Dimitar
Progress Telerik
Thanks Dimitar for your comment. Do you have a sample showing all that? I have been trying so many hours and can't get it to work!
I have created my sub-report, designed it, added a list to my main report (made it public so it can be accessible from the code), and not much is shown:
// Creating a new reportvar report = new rInternalAccountSummary();
report.DataSource = objectDataSource;
report.list1.DataSource = objectDataSourceHoldings;
// Use the InstanceReportSource to pass the report to the viewer for displaying
var reportSource = new Telerik.Reporting.InstanceReportSource();
reportSource.ReportDocument = report;
// Assigning the report to the report viewer.
reportViewer1.ReportSource = reportSource;
// Calling the RefreshReport method (only in WinForms applications).
reportViewer1.RefreshReport();
For the List you may consider the following code:
DataItem list1 = (DataItem)report.Items.Find("list1", true)[0];
list1.DataSource = objectDataSourceHoldings;
You may check also the article Access Report Items Programmatically
Note also that the suggested approach doesn't include SubReport. The latter should be replaced with a List.
Hre is sla
Sorry for the delay, was on vacation last week.
Just tried Todor suggestion and not a winner.
Seems to be quite tough to achieve what I need/want and I can't seem to get a full working example! Pretty bad.
I have attached two sample reports, one to serve as the main report and one to serve as the subreport.
The report that is used by the SubReport item has a binding on its DataSource to be the parent report item's DataObject as shown in the How to bind Sub Report to Main Report's Data KB article. The SubReport item is placed inside a list so the list is its parent and the subreport report will take its data from that list's DataObject.
The following code demonstrates how to edit the list data source. I used the JsonDataSource for the example but it is absolutely the same for all data source components:
private void MainForm_Load(object sender, System.EventArgs e)
{
var report = new MainReport();
var reportList = (Telerik.Reporting.List)report.Items.Find("list1", true)[0];
reportList.DataSource = new JsonDataSource() { Source = "{\"Name\":\"My Name\"}"};
this.reportViewer1.ReportSource = new InstanceReportSource() { ReportDocument = report };
this.reportViewer1.RefreshReport();
}
Hi Dimitri. Looks like your sample is an empty solution. Can you please rezip it?
I have attached only both reports with the correct report structure.
You may add them to your WinForms application or in a referenced class library project and then you may use them in combination with the code from the latest reply.
The report design itself can be seen in the corresponding .Designer.cs files.
If you have trouble opening the reports in your VS Designer, you may try to run the Upgrade Wizard after adding the reports to your solution so that the reports' Telerik Reporting references are with the correct version.