Hyperlinks can be used in ActiveReports to simulate drill-down reporting.
This walkthrough illustrates how to set up hyperlinks in a report to simulate drill-down reporting.
This walkthrough is split up into the following activities:
- Adding three ActiveReports to a Visual Studio project
- Connecting each report to a data source
- Adding controls to each report to display the data
- Adding three Windows Forms with viewer controls to the project
- Adding code to frmViewMain and frmViewDrillDown1
- Adding code to frmViewMain and frmViewDrillDown2
- Adding the code needed to set hyperlink properties
- 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 finished this walkthrough, you will have a main report that looks similar to the following.
Adding three ActiveReports to a Visual Studio project
To add three ActiveReports to a Visual Studio 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 rptMain.
- Click Open.
- Change the BackColor property of the detail section to Thistle.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and rename the file rptDrillDown1.
- Click Open.
- Change the BackColor property of the detail section to RosyBrown.
- From the Project menu, select Add New Item.
- Select ActiveReports 3.0 File and rename the file rptDrillDown2.
- Change the BackColor property of the detail section to LightSteelBlue.
- Click Open.
Connecting rptMain to a data source
To connect the report to a data source
- Click the gray report DataSource icon in the Detail section to open the report DataSource dialog.
- Select the "OLE DB" tab.
- Click Build.
- Select Microsoft Jet 4.0 OLE DB Provider and click Next.
- Click the ellipsis 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 * from customers order by customerID".
- Click OK to return to the report design surface.
Connecting rptDrillDown1 to a data source
To connect the report to a data source
- Click the gray report DataSource icon in the Detail section to open the report DataSource dialog.
- Select the "OLE DB" tab.
- Click Build.
- Select Microsoft Jet 4.0 OLE DB Provider and click Next.
- Click the ellipsis 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 * from orders where customerID = '<%customerID%>' order by orderdate".
- Click OK to return to the report design surface.
- Set the report's ShowParameterUI property to False to avoid displaying a UI requesting parameters.
Connecting rptDrillDown2 to a data source
To connect the report to a data source
- Click the gray report DataSource icon in the Detail section to open the report DataSource dialog.
- Select the "OLE DB" tab.
- Click Build.
- 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.
Setting a default value for the parameter in this query allows you to see fields in the Report Explorer instead of an error message. - Click OK to return to the report design surface.
- Set the report's ShowParameterUI property to False to avoid displaying a UI requesting parameters.
Adding controls to display the data
To add controls to the reports
- Add the following controls to rptMain, setting their properties as indicated:
Control Section Location Name DataField Text Miscellaneous Label PageHeader 0, 0 lblCustomer Customer ForeColor = Purple; Font = 12pt Label PageHeader 1.188, 0 lblCompanyName Company Name ForeColor = Purple; Font = 12pt Label PageHeader 3.563, 0 lblContactName Contact Name ForeColor = Purple; Font = 12pt TextBox Detail 0, 0 txtCustomerID CustomerID Customer ID ForeColor = Blue; Underline = True TextBox Detail 1.183, 0 txtCompanyName CompanyName Company Name ForeColor = Black TextBox Detail 3.563, 0 txtContactName ContactName Contact Name ForeColor = Black - Add the following controls to rptDrillDown1, setting their properties as indicated:
Control Section Location Name DataField Text Miscellaneous Label PageHeader 0,0 lblCustomerID Customer ID ForeColor = Maroon; Font = 12pt Label PageHeader 1.188, 0 lblOrderID Order ID ForeColor = Maroon; Font = 12pt Label PageHeader 2.438, 0 lblEmployeeID Employee ID ForeColor = Maroon; Font = 12pt Label PageHeader 3.625, 0 lblOrderDate Order Date ForeColor = Maroon; Font = 12pt Label PageHeader 4.813, 0 lblShippedDate Shipped Date ForeColor = Maroon; Font = 12pt TextBox Detail 0, 0 txtCustomerID CustomerID Customer ID ForeColor = Black TextBox Detail 1.188, 0 txtOrderID OrderID Order ID ForeColor = Blue; Underline = True TextBox Detail 2.438, 0 txtEmployeeID EmployeeID Employee ID ForeColor = Black TextBox Detail 3.625, 0 txtOrderDate OrderDate Order Date ForeColor = Black TextBox Detail 4.813, 0 txtShippedDate ShippedDate Shipped Date ForeColor = Black - Add the following controls to rptDrillDown2, setting their properties as indicated:
Control Section Location Name DataField Text Miscellaneous Label PageHeader 0, 0 lblOrderID Order ID ForeColor = Navy; Font = 12pt Label PageHeader 1.188, 0 lblProductID Product ID ForeColor = Navy; Font = 12pt Label PageHeader 2.375, 0 lblUnitPrice Unit Price ForeColor = Navy; Font = 12pt Label PageHeader 3.563, 0 lblQuantity Quantity ForeColor = Navy; Font = 12pt Label PageHeader 4.75, 0 lblDiscount Discount ForeColor = Navy; Font = 12pt TextBox Detail 0, 0 txtOrderID OrderID Order ID ForeColor = Black TextBox Detail 1.188, 0 txtProductID ProductID Product ID ForeColor = Black TextBox Detail 2.375, 0 txtUnitPrice UnitPrice Unit Price OutputFormat = Currency TextBox Detail 3.563, 0 txtQuantity Quantity Quantity ForeColor = Black TextBox Detail 4.75, 0 txtDiscount Discount Discount OutputFormat = Currency
Adding three Windows Forms with viewer controls to your project
To add three Windows Forms with viewer controls to your project
- Change the name of the default Windows Form to frmViewMain.
- Place an ActiveReports viewer control on frmViewMain and set its Dock property to Fill.
- From the Project menu, select Add Windows Form.
- Change the name of the Windows Form to frmViewDrillDown1.
- Click Open.
- Place an ActiveReports viewer control on frmViewDrillDown1 and set its Dock property to Fill.
- From the Project menu, select Add Windows Form.
- Change the name of the Windows Form to frmViewDrillDown2.
- Click Open.
- Place an ActiveReports viewer control on frmViewDrillDown2 and set its Dock property to Fill.
Adding code to frmViewMain
To write the code in Visual Basic
- Right-click on frmViewMain to display the code view for the report. At the top left of the code view for frmViewMain, click the drop-down arrow and select Viewer1. At the top right of the code window, click the drop-down arrow and select Hyperlink. This creates an event-handling method for frmViewMain's Viewer1_Hyperlink event.
To write the code in C#
- Click in the Viewer section of frmViewMain to select the viewer. Click on the events icon in the Properties window to display available events for the viewer. Double-click Hyperlink. This creates an event-handling method for frmViewMain's Viewer1_Hyperlink event.
The following example shows what the code for the method looks like.
'Visual Basic Private Sub Viewer1_HyperLink(ByVal sender As Object, ByVal e As DataDynamics.ActiveReports _ .Viewer.HyperLinkEventArgs) Handles Viewer1.HyperLink Dim rpt2 As New rptDrillDown1() Dim frm2 As New frmViewDrillDown1() rpt2.Parameters("customerID").Value = e.HyperLink.ToString rpt2.Run() frm2.My_Viewer.Document = rpt2.Document frm2.ShowDialog(Me) End Sub //C# private void viewer1_HyperLink(object sender, DataDynamics.ActiveReports.Viewer .HyperLinkEventArgs e) { rptDrillDown1 rpt2 = new rptDrillDown1(); frmViewDrillDown1 frm2 = new frmViewDrillDown1(); rpt2.Parameters["customerID"].Value = e.HyperLink.ToString(); rpt2.Run(); frm2.viewer1.Document = rpt2.Document; frm2.ShowDialog(this); }
Adding code to frmViewDrillDown1
To write the code in Visual Basic
- Double-click at the top of frmViewDrillDown1 to display the code view for the report. At the top left of the code view for frmViewDrillDown1, click the drop-down arrow and select Viewer1. At the top right of the code window, click the drop-down arrow and select Hyperlink. This creates an event-handling method for frmViewDrillDown1's Viewer1_Hyperlink event.
To write the code in C#
- Click in the Viewer section of frmViewDrillDown1 to select the viewer. Click on the events icon in the Properties window to display available events for the viewer. Double-click Hyperlink. This creates an event-handling method for frmViewDrillDown's Viewer1_Hyperlink event.
The following example shows what the code for the method looks like.
'Visual Basic Private Sub Viewer1_HyperLink(ByVal sender As Object, ByVal e As DataDynamics _ .ActiveReports.Viewer.HyperLinkEventArgs) Handles Viewer1.HyperLink Dim rpt3 As New rptDrillDown2() Dim frm3 As New frmViewDrillDown2() rpt3.Parameters("orderID").Value = e.HyperLink.ToString rpt3.Run() frm3.My_Viewer.Document = rpt3.Document frm3.ShowDialog(Me) End Sub //C# private void viewer1_HyperLink(object sender, DataDynamics.ActiveReports.Viewer .HyperLinkEventArgs e) { rptDrillDown2 rpt3 = new rptDrillDown2(); frmViewDrillDown2 frm3 = new frmViewDrillDown2(); rpt3.Parameters["orderID"].Value = e.HyperLink.ToString(); rpt3.Run(); frm3.My_Viewer.Document = rpt3.Document; frm3.ShowDialog(this); }
Adding code to frmViewDrillDown
To write the code in Visual Basic
- Double-click at the top of frmViewDrillDown1 to display the code view for the report. At the top left of the code view for frmViewDrillDown1, click the drop-down arrow and select Viewer1. At the top right of the code window, click the drop-down arrow and select Hyperlink. This creates an event-handling method for frmViewDrillDown1's Viewer1_Hyperlink event.
To write the code in C#
- Click in the Viewer section of frmViewDrillDown1 to select the viewer. Click on the events icon in the Properties window to display available events for the viewer. Double-click Hyperlink. This creates an event-handling method for frmViewDrillDown's Viewer1_Hyperlink event.
The following example shows what the code for the method looks like.
'Visual Basic 'Create a property to return the ActiveReports viewer Friend ReadOnly Property My_Viewer() As DataDynamics.ActiveReports.Viewer.Viewer Get Return Me.Viewer1 End Get End Property //C# //Create a property to return the ActiveReports viewer. internal DataDynamics.ActiveReports.Viewer.Viewer My_Viewer { get { return this.viewer1; } }
Adding the code needed to set the hyperlink property for rptMain
To write the code in Visual Basic
- Right-click in any section of the design window of rptMain, and click on View Code to display the code view for the report. At the top left of the code view for rptMain, click the drop-down arrow and select Detail. At the top right of the code window, click the drop-down arrow and select BeforePrint. This creates an event-handling method for rptMain's Detail_BeforePrint event.
To write the code in C#
- Click in the Detail section of rptMain to select the section. Click on the events icon in the Properties window to display available events for the section. Double-click BeforePrint. This creates an event-handling method for rptMain's Detail_BeforePrint event.
The following example shows what the code for the method looks like.
'Visual Basic Private Sub Detail1_BeforePrint(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles Detail1.BeforePrint Me.txtCustomerID.HyperLink = Me.txtCustomerID.Text End Sub //C# private void detail_BeforePrint(object sender, System.EventArgs eArgs) { this.txtCustomerID.HyperLink = this.txtCustomerID.Text; }
Adding the code needed to set the hyperlink property for rptDrillDown1
To write the code in Visual Basic
- Right-click in any section of the design window of rptDrillDown1, and click on View Code to display the code view for the report. At the top left of the code view for rptDrillDown1, click the drop-down arrow and select Detail. At the top right of the code window, click the drop-down arrow and select BeforePrint. This creates an event-handling method for rptDrillDown1's Detail_BeforePrint event.
To write the code in C#
- Click in the Detail section of rptDrillDown1 to select the section. Click on the events icon in the Properties window to display available events for the section. Double-click BeforePrint. This creates an event-handling method for rptDrillDown1's Detail_BeforePrint event.
The following example shows what the code for the method looks like.
'Visual Basic Private Sub Detail1_BeforePrint(ByVal sender As Object, ByVal e As System.EventArgs) _ Handles Detail1.BeforePrint
Me.txtOrderID.HyperLink = Me.txtOrderID.Text
End Sub//C#
private void detail_BeforePrint(object sender, System.EventArgs eArgs)
{
this.txtOrderID.HyperLink = txtOrderID.Text;
}
Viewing the report
To view the report
- Add the code needed to set the viewer document of frmViewMain equal to the document for rptMain. See Using the ActiveReports Windows Form Viewer for help.
- Click the hyperlink in frmViewMain to drill-down to the next report level.
You can quickly view your report at design time by clicking the Preview tab at the bottom of the designer. |