Question

I'm trying to create a report in my WPF application. I'm using Visual Studio 2010, C# and MVVM

I have researched alot and only found articles on the net that deal with Crystal Report by using a database. In my application, I don't communicate with the database directly. We use a web service. It communicates with the database and writes all the data in xml files. We get our info via stored procedures. Hopefully that is not a problem.

Anyway, on one of my User Controls, I have a datagrid that is populated with data from the database. I store this data using a List and Observable Collection. So retreiving the data is easy. But I would now like to export the data into a report for the user to print.

As I said, I've read up on reports, and they all use some form of dataset or datatable. But as I've stated, we don't use the database directly.

I have downloaded the SAP Crystal Reports, developer version for Microsoft Visual Studio: Updates & Runtime Downloads just to ensure I can use Crystal Reports.

I have an idea that I must create a new User Control or Window View and set the datacontext via ViewModel. On this form should be a Report Viewer control, that would be populated. But I don't know what to pass through, if I can do something like this. Can I send over the List/ObservableCollection that has the data I want saved to the form, and bind it to the report control? Using [this] as an example 2, this is kind of the direction I'm looking for

Or is there another way of creating a report without using a database? I just generally want to create a report in my existing WPF project. A new window or user control is opened and the report viewer is loaded here, with the data I have in a gridview. Using WPF and MVVM, how do I achieve this.

I also have Component One if anybody knows how to use this. The website itself doesn't offer great tutorials on the subject of thier report views.

Please let me know if there is anything else you need from me, and I'll make edits where I can

Was it helpful?

Solution

I think you're on the right track by creating a user control that uses the data grid. I think the next thing you want to look into for printing some kind of reports is DocumentPaginator. Using this approach you can print to .XPS files, print the user control right to paper, or/and use a third-party XPS to PDF converter.

Here is an example to get you started!

OTHER TIPS

Just started looking at this myself, firstly you can add a DataSource based on either your EF context or your web service. You can then use the built in reporting toolset (which is based on the SQL Server Report Services (though you dont need this to host them)).

Though you'll need to use the Windows Forms host control :( MSDN walkthrough about hosting reports in WPF

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top