Walkthrough Keep Together Options

ActiveReports allows you to set KeepTogether options for your reports so that 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 (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

1. Open a new project in Visual Studio.

2. Click on Project > Add New Item.

3. Select ActiveReports file and rename the file rptKeepTG.

4. Click Open.

Connecting the report to a data source To connect the report to a data source

1. Click on the yellow report DataSource icon in the Detail section. This brings up the report DataSource dialog box.

3. Select Microsoft Jet 4.0 OLE DB Provider and click Next >>

4. Click on the ellipsis to browse for the access path to NWind.mdb. Click Open once you have selected the appropriate access path.

5. Click OK to continue.

6. In the Query field, type "SELECT DISTINCTROW Orders.*, [Order Details].*, Products.* FROM Products INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.OrderlD = [Order Details].OrderID) ON Products.ProductID = [Order Details].ProductID order by orderdate".

7. Click OK to return to the report design surface.

Adding controls to the report to contain data To add controls to the report

1. Add a GroupHeader/Footer section to rptKeepTG (see Grouping Data for help).

2. Make the following changes to the group header:

o Change the name to ghOrders o Change the DataField to OrderDate o Change the GroupKeepTogether property to All o Change the KeepTogether property to True

3. Add the following controls to the GroupHeader section:

Control Name Text/Caption Location



Order Date

0, 0



Order ID

1.125, 0



Product Name

2.239, 0




3.5, 0



Unit Price

4.75, 0

4. Add the following controls to the Detail section:

Control DataField Name Text/Caption orders.OrderlD txtOrderID Order ID

TextBox TextBox TextBox

TextBox TextBox

ProductName txtProductName Product Name products.UnitPrice txtUnitPrice Unit Price

OrderDate Quantity txtOrderDate txtQuantity

Order Date Quantity


Output Format

(Empty string) (Empty string) Currency

(Empty string) (Empty string)

Viewing the report To view the report

1. Add the ActiveReports viewer control to a Windows Form.

2. Add the code needed to set the viewer document equal to the report document. See Using the ActiveReports WinForm Viewer for help.

Was this article helpful?

0 0

Post a comment