ActiveReports allows you to set KeepTogether options for your reports so that the group detail is kept together on one page when printed.
This walkthrough illustrates how to set the KeepTogether and GroupKeepTogether options to allow all group detail to print together on one page.
This walkthrough is split up into the following activities:
- Adding an ActiveReport to a Visual Studio project
- Connecting the report to a data source
- Adding controls to the report to contain data
- Viewing the report
To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\Data Dynamics\ActiveReports for .NET 3.0\Data\NWIND.MDB.
When you have completed this walkthrough, you will have a report that looks similar to the following.
Adding an ActiveReport to a Visual Studio project
To add an ActiveReport to your project
- Open a new project in Visual Studio.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and rename the file rptKeepTG.
- Click Open.
Connecting the report to a data source
To connect the report to a data source
- Click on the gray report DataSource icon in the Detail section to open the report DataSource dialog.
- Select the "OLE DB" tab.
- Click the Build button.
- Select Microsoft Jet 4.0 OLE DB Provider and click Next.
- Click the ellipsis button to browse for the access path to the Northwind database. Click Open once you have selected the appropriate access path.
- Click OK to continue.
- In the Query field, type "SELECT DISTINCTROW Orders.*, [Order Details].*, Products.* FROM Products INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID order by orderdate".
- Click OK to return to the report design surface.
Adding controls to the report to contain data
To add controls to the report
- Add a GroupHeader/Footer section to rptKeepTG by right-clicking the design surface of the report and selecting Insert > Group Header/Footer.
- Make the following changes to the group header:
- Change the Name property to ghOrders
- Change the BackColor property to RosyBrown
- Change the DataField property to OrderDate
- Change the GroupKeepTogether property to All
- Change the KeepTogether property to True
- Add the following controls to the GroupHeader section:
Control Name Text Location Label lblOrderDate Order Date 0, 0 Label lblOrderID Order ID 1.13, 0 Label lblProductName Product Name 2.24, 0 Label lblQuantity Quantity 4.63, 0 Label lblUnitPrice Unit Price 5.5, 0 - In the Report Explorer, expand the Fields node, then the Bound node. Drag the following fields onto the detail section and set the following properties of each textbox as indicated.
Field Text Location Output Format orders.OrderID Order ID 1.13, 0 ProductName Product Name 2.24, 0 products.UnitPrice Unit Price 5.5, 0 Currency
OrderDate Order Date 0, 0 MM/dd/yy Quantity Quantity 4.63, 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 Windows Form Viewer for help.
You can quickly view your report at design time by clicking the Preview tab at the bottom of the designer. |