Sei sulla pagina 1di 3

ActiveReports allows you to create Master Detail reports with grouping by using the

GroupHeader and Detail sections to contain data from master files and detail files.
This walkthrough illustrates how to create a Master Detail report using grouping to organize
the report.
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
1. Open a new project in Visual Studio.
2. From the Project menu, select Add New Item.
3. Select ActiveReports 3.0 File and rename the file rptMD.
4. Click Open.

Connecting the report to a data source


To connect the report to a data source
1. Click on the gray report DataSource icon in the Detail section to open the report
DataSource dialog box.
2. Select the "OLE DB" tab.

3. Click the Build button.


4. Select Microsoft Jet 4.0 OLE DB Provider and click Next.
5. Click the ellipsis button to browse for the access path to the Northwind database.
Click Open once you have selected the appropriate access path.
6. Click OK to continue.
7. In the Query field, type "Select * from orders, [order details], products where
orders.OrderID = [order details].OrderID and products.productID = [order
details].productID order by OrderDate".
8. Click OK to return to the report design surface.

Adding controls to the report to contain data


To add controls to the report
1. Change the BackColor property of the page header to Silver.
2. Add labels to the page header with the following properties set:
Name
lblOrderDate
lblShipName
lblShippedDate
lblShipAddress
lblShipCountry

Text
Order Date
Ship Name
Shipped Date
Ship Address
Ship Country

Font Style
Bold
Bold
Bold
Bold
Bold

Location
0, 0
1, 0
3, 0
4, 0
5.5, 0

3. Add a GroupHeader/Footer section to rptMD by right-clicking the design surface of


the report and selecting Insert > Group Header/Footer.
4. Make the following changes to the group header:
o Change the Name property to ghOrders
o Change the BackColor property to LightGray
o Change the DataField property to orders.OrderID
5. In the Report Explorer, expand the Fields node, then the Bound node. Drag the
following fields onto ghOrders and set the properties as indicated.
DataField
OrderDate
ShipName
ShippedDate

Name
txtOrderDate1
txtShipName1
txtShippedDate1

Text
Order Date
Ship Name
Shipped Date

OutputFormat
MM/dd/yy
MM/dd/yy

Location
0, 0
1, 0
3, 0

ShipAddress
ShipCountry

txtShipAddress1
txtShipCountry1

Ship Address
Ship Country

4, 0
5.5, 0

6. Add another GroupHeader/Footer section to your report.


7. Change the BackColor property of the group header to LightSteelBlue.
8. Add labels to the group header with the following properties set:
Name
lblOrderID
lblProductName
lblProductID
lblUnitPrice
lblQuantity

Text
Order ID
Product Name
Product ID
Unit Price
Quantity

Font Style
Bold
Bold
Bold
Bold
Bold

Location
0, 0
1, 0
3, 0
4, 0
5.5, 0

9. Make the following changes to the detail section:


o Change the BackColor property to AliceBlue
o Change the CanShrink property to True
10. In the Report Explorer, expand the Fields node, then the Bound node. Drag the
following fields onto the detail section and set the properties as indicated.
DataField
orders.OrderID

Name
txtOrderID1

Text
Order ID
Product
ProductName
txtProductName1
Name
products.ProductID txtProductID1
Product ID
products.UnitPrice

txtUnitPrice1

Unit Price

Quantity

txtQuantity1

Quantity

Miscellaneous

Location
0, 0
1, 0
3, 0

OutputFormat =
Currency

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 Windows Form Viewer for help

4, 0
5.5, 0