How to create a report from WPF app using data from IEnumerable

1 Answer 80 Views
DataSource Object Report Designer (standalone)
Kay
Top achievements
Rank 1
Kay asked on 15 Apr 2023, 05:26 PM | edited on 17 Apr 2023, 11:14 AM

Our app interacts with the user asking for datasource and let the user select columns, sorting, groups etc und presents the resulting data in a DataGrid.  Now we want to display the data in a report that is created by the user. 
We use .NET 6.0, WPF and Telerik.Reporting 17
I have searched for a solution, but there are too mutch examples which no longer function at all.
- I did not find a solution using embeded ReportDesigner because apparently no embedded designer exists anymore
- I did not find a solution with the external ReportDesigner because I could not transfer the data from the app to the designer.
How can I accomplish my task?

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 19 Apr 2023, 02:22 PM

Hello Kay,

Thank you for the provided information!

By embedded Report Designer, I assume that you mean the Visual Studio Report Designer. This designer still does exist, however, it has not yet been implemented for .NET Core projects and currently works only in projects that use .NET Framework.

With that being said, you can achieve the desired result using the external Standalone Report Designer to design a TRDP/TRDX report. While this designer cannot interact with your application's runtime data, you do not need to. You can create a report in the external designer using some "dummy" or real data that you will replace when the report is displayed in your application with the runtime data.

Since the user will be selecting the columns and such, you will probably need a report that dynamically creates columns from its data. We have several articles that cover such scenarios:

Once you have set up the report, you will only need to pass it the runtime data when it is ready. That is done by unpackaging the report, editing the generated Telerik.Reporting.Report object and then wrapped it in an InstanceReportSource for the WPF Report Viewer.

For example:

        public MainWindow()
        {

            this.InitializeComponent();
           
            string reportPath = "C:\\temp\\Report1.trdp";
            var reportPackager = new ReportPackager();
            Report report = null;
            using (var sourceStream = System.IO.File.OpenRead(reportPath))
            {
                report = (Report)reportPackager.UnpackageDocument(sourceStream);
            }

                // Set the data source for the report
                report.DataSource = MyService.GetMyData();
                // Set the data source for another data item
                var table1 = report.Items.Find("table1", true)[0] as Table;
                table1.DataSource = MyService.GetMyTableData();
                
              var instanceReportSource = new InstanceReportSource() { ReportDocument = report };
              this.ReportViewer1.ReportSource = instanceReportSource;
        }

If the above approaches are not flexible enough, you can even create the report dynamically with code:

I hope that the suggested approaches will help, please do not hesitate to let me know if you have additional questions.

Regards,
Dimitar
Progress Telerik

Brand new Telerik Reporting course in Virtual Classroom - the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products. Check it out at https://learn.telerik.com/.
Tags
DataSource Object Report Designer (standalone)
Asked by
Kay
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or