Most of the modern reporting tools allow you to use almost any database. However, not all of them can work with lists or arrays of objects as a data source. In this article I'll show how to do it on the example of FastReport .Net reporting tool.
I will mention some important points:
• object fields from the list should be described as a public property to be visible in the report;
• in addition to the lists you can send in your report data from any iEnumerable collections;
• to transfer linq query results in the report you need to convert list using ToArray method.
Create a Windows Forms application.
Give a list of categories in the report. For each category there will be added the list of products.
As the name suggests, it is a list of categories and report object.
So, add a class of products:
As you can see, the fields of the object declared as public.
Now add the class of categories:
One of the fields of the object Category is a list of products. That is, a list of categories is an array of arrays.
Let's create a data source:
From the comments it is clear that a list of objects Category is created. Then create a new category and add the desired number of products to it. Then add the category in the categories list. So we add a few categories with products.
We have created a data source. Now you need to register the report with the help of RegisterData method:
This method will make your list available in the report with the name: "Categories".
Add a method of running the report in the designer:
Here we have created an instance of the report object and data source. Also we registered data source and opened the report in the designer.
Add a button of the method of calling the report designer:
In the report designer, you need to select a data source in the menu Data -> Choose Report Data ...
Create a simple report of the Master-Detail type:
And run the report in preview mode:
To sum up: FastReport .Net once again proved being a flexible, modern product. You can use necessary data from your application without having to worry about converting them into DataTable.