ActiveReports supports newspaper column layouts in both the Detail and Group sections. You can render the columns either horizontally or vertically in the section with options to break the column on the Group section (i.e. start a new column on the change of a group). There is also a Boolean ColumnGroupKeepTogether property on the GroupHeader. When set to True, the ColumnGroupKeepTogether property attempts to prevent a group from splitting across columns. If a group cannot fit in the current column, it tries the next. If the group is too large for a single column, the property is ignored.
|
Note: The ColumnGroupKeepTogether property is only implemented when the GroupHeader's GroupKeepTogether property is set to All. |
This walkthrough illustrates how to create a simple report using columns, and is split up into the following activities:
- Connecting the report to a data source
- Adding controls to the report to display data
|
Tip: For basic steps like adding a report to a Visual Studio project and viewing a report, please see the Basic Data Bound Reports walkthrough. |
To complete the walkthrough, you must have access to the Northwind database.
A copy is located at C:\Program Files\GrapeCity\ActiveReports 6\Data\NWIND.MDB (on a 64-bit Windows operating system, a copy is located in C:\Program Files (x86)\GrapeCity\ActiveReports 6\Data\NWIND.MDB).
When you have finished this walkthrough, you will have a report that looks similar to the following.
To connect the report to a database
- Add a report to a Visual Studio project, naming it rptColumnar.
- Click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog.
- On the OLE DB tab, next to Connection String, click the Build button.
- In the Data Link Properties window that appears, select Microsoft Jet 4.0 OLE DB Provider and click the Next button.
- Click the ellipsis (...) button to browse to the Northwind database. Click Open once you have selected the appropriate access path.
- Click OK to close the window and fill in the Connection String field.
- In the Query field, enter the following SQL query
SQL Query |
Copy Code |
SELECT Country, CompanyName, ContactName, Phone FROM Customers ORDER BY Country |
- Click OK to save the data source and return to the report design surface.
To add controls to the report
- Add a GroupHeader/Footer section to rptColumnar by right-clicking on the design surface of the report and selecting Insert, then Group Header/Footer.
- Select the group header and, in the Properties Window, make the following changes:
- Change the Name property to ghCountry.
- Change the BackColor property to Gold.
- Change the DataField property to Country.
- Change the ColumnGroupKeepTogether property to True to attempt to prevent groups from splitting across columns.
- Change the GroupKeepTogether property to All to enable the ColumnGroupKeepTogether property.
- Change the CanShrink property to True to eliminate white space after each name.
- Select the group footer, and change its BackColor property to Goldenrod.
- Drag the Country field from the Report Explorer into the GroupHeader section, and set its properties as indicated:
Alignment |
Font |
Location |
Size |
Center |
Arial, 12pt, style=Bold |
0, 0 |
3.25, 0.2 in |
- Select the PageHeader section and change its BackColor property to Linen.
- Drag a Label control from the ActiveReports toolbox into the PageHeader section, and set its properties as indicated:
Alignment |
Font |
Text |
Location |
Size |
Center |
Arial, 14pt |
Customer Telephone List by Country |
0, 0 |
6.5, 0.25 in |
- Select the Detail section, and make the following changes in the Properties Window:
- Change the CanShrink property to True to eliminate white space after each name.
- Change the ColumnCount property to 2 to split the detail section into two columns.
- Drag the following fields from the Report Explorer into the Detail section and set their properties as indicated:
Field |
Font |
Location |
Size |
CompanyName |
Arial, 8pt |
0, 0 in |
1.15, 0.2 in |
ContactName |
Arial, 8pt |
1.16, 0 in |
1.15, 0.2 in |
Phone |
Arial, 8pt |
2.3, 0 in |
0.95, 0.2 in |
See Also