List Control for Hierarchical Relationships
In This Topic
This article demonstrates the steps to create a simple list and a hierarchical list using the List control in ActiveReports.
Create Simple List
Let’s create a report that shows the products information for each category, so the product details will appear corresponding to each category, along with the category name and category description. The report uses 'NWIND.db' data source available on GitHub. It is a SQLite Provider, a custom data provider that works if System.Data.SQLite package is added and referenced in the ActiveReports.config file. See setting up the dependencies and configuration file as described in Configure ActiveReports using Config File topic.
The report uses the List data region with other controls on it so that each control repeats for every record in the dataset. The report also uses a Table to show the details corresponding to each category. The List data region uses detail grouping by the CategoryName grouping value.
The final report will look like as shown.
Create a Report
In the ActiveReports Designer, create a new RDLX report.
If you are creating a new report in the Visual Studio Integrated Designer, see
Quick Start.
Bind Report to Data
As you create a new report, you can configure the report data connection in the Report Wizard. You can also access the Report Data Source dialog by right-clicking the Data Sources node in the Report Explorer and then selecting the Add Data Source option. See SQLite for details.
- On the Choose Data Source Type screen of the wizard, select SQLite and click Next.
- To specify the DataBase Path, click the Browse button and navigate to the desired file on your system. For example, you can connect to the Reels.db sample data source which can be downloaded from GitHub.
- Click Test Connection to test the connection.
- Then click the Next option and configure the dataset by adding a valid query.
Dataset Query |
Copy Code
|
SELECT Movie.Title, Genre.GenreName, Movie.MovieID, Movie.Length, Movie.YearReleased, Movie.UserRating, Movie.MPAA, Movie.Country
FROM Genre INNER JOIN (Movie INNER JOIN MovieGenres ON Movie.MovieID = MovieGenres.MovieID) ON Genre.GenreID = MovieGenres.GenreID;
|
- Into the Name field, enter the name of the dataset as MoviesDataset.
- Click Next to proceed to the final screen of the Report Wizard.
- On the final screen of the Report Wizard, review the summary of the report and click Finish to successfully add the report with the SQLite data source.
Design Report Layout
- Drag and drop the List data region (List1) on the report’s designer.
- With the List selected, click Property dialog to open the List dialog.
- In the List dialog, go to Detail Grouping and set the Group on expression =Fields!Title.Value.
- Drag and drop the TextBox control onto the List data region and bind it to the [Title] field. This will be the header of each catalog entry for a movie.
- Next, drag and drop few TextBox controls below the [Title] textbox on the List2, and set their Value property as follows:
- TextBox2: Released Year:
- TextBox3: =Fields!YearReleased.Value
- TextBox4: Country:
- TextBox5: =Fields!Country.Value
- TextBox6: MPAA Rating:
- TextBox7: =Fields!MPAA.Value
- TextBox8: Length:
- TextBox9: ="Length: " & Fields!Length.Value & " min"
- TextBox10: =Fields!UserRating.Value
- To add the report title, drag and drop the TextBox control to the PageHeader section and set its Value property to 'Movies Catalog'.
- Improve the appearance of the report and preview.
Create Hierarchical List
You can create reports with hierarchies of expanded lists, using the List control. The report uses 'reels.db' data source available on GitHub. It is a SQLite Provider, a custom data provider that works if System.Data.SQLite package is added and referenced in the ActiveReports.config file. See setting up the dependencies and configuration file as described in Custom Data Provider topic.
The report displays the movies catalog with the list of movies along with the movies information. The report data is grouped by genre and title of the movies.
The final report will look like as shown.
Create a Report
In the ActiveReports Designer, create a new RDLX report.
Bind Report to Data
Connect to a Data Source
- As you create a new report, the Report Data Source dialog appears for you to configure the report data connection. You can also access this dialog by right-clicking the Data Sources node in the Report Explorer and then selecting the Add Data Source option.
- In the dialog, select the General page and enter the name of the data source, 'ReelsDataSource'.
- Under Type, select 'SQLite Provider'.
- In the Connection String, enter the path of the .db, here, 'reels.db', for example
Connection String |
Copy Code
|
Data Source=C:\Data\reels.db
|
- Click OK to close the dialog and complete the data source connection.
Add Dataset
- Right-click the added data source and select Add Dataset.
- In the Dataset dialog, select the General page and enter the name of the dataset, 'MoviesDataset'.
- Go to the Query tab and enter the following query to fetch the required fields:
Dataset Query |
Copy Code
|
SELECT Movie.Title, Genre.GenreName, Movie.MovieID, Movie.Length, Movie.YearReleased, Movie.UserRating, Movie.MPAA, Movie.Country
FROM Genre INNER JOIN (Movie INNER JOIN MovieGenres ON Movie.MovieID = MovieGenres.MovieID) ON Genre.GenreID = MovieGenres.GenreID;
|
Design Report Layout
- Drag and drop the List data region (List1) on the report’s designer.
- With the List selected, click Property dialog to open the List dialog.
- In the List dialog, go to Detail Grouping and set the Group on expression to =Fields!GenreName.Value.
- Drag and drop the TextBox control on to the List data region and bind it to the [GenreName] field. This will be the header of the catalog section.
- Drag and drop another List data region (List2) onto the first List.
- Click Property dialog to open the List dialog.
- In the List dialog, go to Detail Grouping and set the Group on expression =Fields!Title.Value.
- Drag and drop the TextBox control onto the List data region and bind it to the [Title] field. This will be the header of each catalog entry for a movie.
- Next, drag and drop few TextBox controls below the [Title] textbox on the List2, and set their Value property as follows:
- TextBox3: Release Year:
- TextBox4: =Fields!YearReleased.Value
- TextBox5: Country:
- TextBox6: =Fields!Country.Value
- TextBox7: MPAA Rating:
- TextBox8: =Fields!MPAA.Value
- TextBox9: Length:
- TextBox10: =Fields!Length.Value & " min"
- TextBox11: =Fields!UserRating.Value
- To add the report title, drag and drop the TextBox control to the PageHeader section and set its Value property to 'Movies Catalog'.
- Improve the appearance of the report and preview.
See Also