Walkthrough: Group on Simple Fields
In ActiveReports, reports can be grouped by using a group header with the DataField property set to the database field on which it is being grouped. ActiveReports allows up to 32 nested groups in a single report. When using grouping, make sure the returned data set is ordered by the fields on which it is being grouped.
This walkthrough illustrates the basics of setting up grouping on simple fields in a report.
The walkthrough is split up into the following activities:
- Adding an ActiveReport to your project
- Connecting the data source to a database
- Adding controls to the report to contain data
- Viewing the report
To complete the walkthrough, you must have access to the NorthWind database (Nwind.mdb).
When you have finished this walkthrough, you will have a report that looks similar to the following.

Adding an ActiveReport to your project
To add an ActiveReport to your project
- Click on Project > Add New Item....
- Click on ActiveReports File to select it.
- Change the name of the report to rptSimpleGroup and click Open.
- The ActiveReports design surface is displayed.
Connecting the data source to a database
To connect the data source to a database
- Click on the yellow report DataSource icon in the Detail section. This brings up the report DataSource dialog box.
- Click on Build...
- Select "Microsoft Jet 4.0 OLE DB Provider" and click Next >>.
- Click on the ellipsis to browse for the access path to Nwind.mdb. Click Open once you have selected the appropriate access path.
- Click OK to continue.
- In the Query field, type "Select * from customers ORDER BY country".
- Click OK to return to the report design surface.
Adding controls to contain data
To add controls to the report
- Add a GroupHeader/Footer section to your report (see Grouping Data for help).
- Make the following changes to the group header:
- Change the name to ghOrderGroup
- Change the DataField property to Country
- Add the following controls to the PageHeader section:
| Control |
Name |
Text/Caption |
Location |
| Label |
lblCustomerID |
Customer ID |
0, 0 |
| Label |
lblCompanyName |
Company Name |
1.0729, 0 |
| Label |
lblContactName |
Contact Name |
2.1875, 0 |
| Label |
lblContactTitle |
Contact Title |
3.3125, 0 |
- Add the following controls to the GroupHeader section:
| Control |
DataField |
Name |
Text/Caption |
Location |
| Textbox |
Country |
txtCountry |
Country |
0.3125, 0.0625 |
- Add the following controls to the Detail section:
| Control |
DataField |
Name |
Text/Caption |
Location |
| Textbox |
CustomerID |
txtCustomerID |
Customer ID |
0, 0 |
| Textbox |
CompanyName |
txtCompanyName |
Company Name |
1.0625, 0 |
| Textbox |
ContactName |
txtContactName |
Contact Name |
2.1875, 0 |
| Textbox |
ContactTitle |
txtContactTitle |
Contact Title |
3.3125, 0 |
Viewing the report
To view the report
- Add the ActiveReports viewer control to a Windows Form.
- Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports WinForm Viewer for help.
Samples | Walkthroughs
Copyright © 2004-2005 Data Dynamics, Ltd. All rights reserved.