ActiveReports 6 Online Help Send comments on this topic.
Hyperlinks for Simulated Drill-Down Reporting
See Also
ActiveReports 6 > ActiveReports User Guide > Samples and Walkthroughs > Walkthroughs > Hyperlinks for Simulated Drill-Down Reporting

Glossary Item Box

Hyperlinks can be used in ActiveReports to pass values to parameters in other reports. 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:

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 reports that look similar to the following.


Click to EnlargeClick to Enlarge

Click to EnlargeClick to Enlarge

Click to EnlargeClick to Enlarge

To connect three reports to data sources

  1. Add three reports to a Visual Studio project, naming them rptCustomers, rptOrders, and rptProductDetails.
  2. On rptCustomers, click the gray report DataSource icon on the Detail section band to open the Report Data Source dialog.
  3. On the OLE DB tab, next to Connection String, click the Build button.
  4. In the Data Link Properties window that appears, select Microsoft Jet 4.0 OLE DB Provider and click the Next button.
  5. Click the ellipsis (...) button to browse to the Northwind database. Click Open once you have selected the appropriate access path.
  6. Click OK to close the window and fill in the Connection String field.
  7. In the Query field, enter the following SQL query
    SQL Query Copy Code
    SELECT CompanyName, ContactName, Phone, CustomerID FROM Customers ORDER BY CustomerID
  8. Click OK to save the data source and return to the report design surface.
  9. On rptOrders, click the gray report DataSource icon on the Detail section band and connect it to Nwind.mdb.
  10. In the Query field, enter the following SQL query
    SQL Query Copy Code
    SELECT Orders.OrderID, Orders.CustomerID, Orders.OrderDate, Orders.ShippedDate, [Order Details].ProductID, 
    Products.ProductName, [Order Details].UnitPrice, [Order Details].Quantity, [Order Details].Discount
    FROM Products INNER JOIN (Orders INNER JOIN [Order Details] ON Orders.OrderID = [Order Details].OrderID) 
    ON Products.ProductID = [Order Details].ProductID
    WHERE Orders.CustomerID = '<%CustomerID||ALFKI%>'
    ORDER BY Orders.OrderID, Products.ProductName
    
  11. Click OK to save the data source and return to the report design surface.
    Note: The SQL queries for rptOrders and rptProductDetails use parameters syntax: '<%CustomerID||ALFKI%>' and <%ProductID||1%>. Using a default value allows the Report Explorer to populate so you can drag fields onto the report. For more information on parameters, see the Parameters topic.
  12. On rptProductDetails, click the gray report DataSource icon on the Detail section band and connect it to Nwind.mdb.
  13. In the Query field, enter the following SQL query
    SQL Query Copy Code
    SELECT Products.ProductID, Products.ProductName, Suppliers.CompanyName, Categories.CategoryName, Products.QuantityPerUnit, 
    Products.UnitPrice, Products.UnitsInStock, Products.UnitsOnOrder, Products.ReorderLevel, Products.Discontinued
    FROM Categories 
    INNER JOIN (Suppliers INNER JOIN Products ON Suppliers.SupplierID = Products.SupplierID) 
    ON Categories.CategoryID = Products.CategoryID
    WHERE Products.ProductID = <%ProductID||1%>
    
  14. Click OK to save the data source and return to the report design surface.

To format the reports and add controls to display data

Top-level Report: rptCustomers

  1. In the design view of rptCustomers, click to select the page header section, and in the Properties Window, change the following properties:
    • BackColor: Gainsboro
    • Height: 0.5
  2. Select the detail section, and set its properties as follows:
    • BackColor: GhostWhite
    • CanShrink: True
  3. Add the following controls to the indicated sections rptCustomers, setting their properties as indicated:

    ShowrptCustomers controls

    Control Section Location Size DataField Text Miscellaneous
    Label PageHeader 0, 0 in 6.5, 0.198 in Customers Alignment = Center
    BackColor = SlateBlue
    ForeColor = White
    Font Size = 12
    Font Style = Bold
    Label PageHeader 0, 0.26 in 1.1, 0.198 in Company Name ForeColor = SlateBlue
    Font Style = Bold
    Label PageHeader 2.6, 0.26 in 1, 0.198 in Contact Name ForeColor = SlateBlue
    Font Style = Bold
    Label PageHeader 4.3, 0.26 in 1, 0.198 in Phone ForeColor = SlateBlue
    Font Style = Bold
    Label PageHeader 5.5, 0.26 in 1, 0.198 in View Orders ForeColor = SlateBlue
    Font Style = Bold
    TextBox Detail 0, 0 in 2.55, 0.2 in CompanyName
    TextBox Detail 2.6, 0 in 1.6, 0.2 in ContactName
    TextBox Detail 4.3, 0 in 1, 0.2 in Phone
    TextBox Detail 5.5, 0 in 1, 0.2 in CustomerID (Name) = txtCustomerID1

Mid-level Report: rptOrders

  1. In the design view of rptOrders, click to select the page header section, and set its Height property to 0.5.
  2. Add the following controls to the page header section, setting their properties as indicated:

    ShowPage header controls for rptOrders

    Control Location Size DataField Text Miscellaneous
    TextBox 0, 0 in 6.5, 0.198 in ="Orders for Customer: " + CustomerID Alignment = Center
    Font Size = 12pt
    Font Style = Bold
    Label 0, 0.25 in 6.5, 0.198 in Return to Customers Alignment = Center
    HyperLink = Customers\\Main
  3. Right-click the report and select Insert, then GroupHeader/Footer.
  4. Set the group header properties as follows:
    • BackColor: LightCyan
    • DataField: OrderID
    • Height: 0.5
  5. Add the following controls to the group header section, setting their properties as indicated:

    ShowGroup header controls for rptOrders

    Control Location Size DataField Text Miscellaneous
    Label 0, 0 in 1, 0.198 in Order Number BackColor = PaleTurquoise
    Font Style = Bold
    TextBox 1, 0 in 0.5, 0.2 in OrderID BackColor = PaleTurquoise
    Label 2.26, 0 in 1, 0.198 in Order Date Alignment = Right
    Font Style = Bold
    TextBox 3.34, 0 in 1, 0.2 in OrderDate Alignment = Right
    OutputFormat = MM/dd/yy
    Label 4.44, 0 in 1, 0.198 in Date Shipped Alignment = Right
    Font Style = Bold
    TextBox 5.5, 0 in 1, 0.2 in ShippedDate Alignment = Right
    OutputFormat = MM/dd/yy
    Line X1 = 0
    X2 = 6.5
    Y1 = 0.2
    Y2 = 0.2
    Label 0, 0.29 in 1, 0.198 in Product ID Font Style = Bold
    Label 1, 0.29 in 1, 0.198 in Product Name Alignment = Right
    Font Style = Bold
    Label 3.34, 0.29 in 1, 0.198 in Unit Price Alignment = Right
    Font Style = Bold
    Label 4.44, 0.29 in 1, 0.198 in Quantity Alignment = Right
    Font Style = Bold
    Label 5.5, 0.29 in 1, 0.198 in Discount Alignment = Right
    Font Style = Bold
  6. Click in the grey area below the report to select it, and set the ShowParameterUI property to False to avoid requesting parameters from the user.
  7. Select the detail section, and set its CanShrink property to True.
  8. From the Report Explorer, drag the following fields onto the detail section of rptOrders, setting their properties as indicated:

    ShowDetail section controls for rptOrders

    Field Location Size Miscellaneous
    ProductID 0, 0 in 0.7, 0.2 in Alignment = Right
    (Name) = txtProductID1
    ProductName 1, 0 in 2.2, 0.2 in
    UnitPrice 3.34, 0 in 1, 0.2 in Alignment = Right
    OutputFormat = $#,##0.00
    Quantity 4.44, 0 in 1, 0.2 in Alignment = Right
    Discount 5.5, 0 in 1, 0.2 in Alignment = Right
    OutputFormat = 0%

Lowest-Level Report: rptProductDetails

  1. Add a textbox to the page header section of rptProductDetails, setting its properties as indicated:

    ShowrptProductDetails controls

    Control Location Size DataField Miscellaneous
    TextBox 0, 0 in 6.5, 0.2 in ="Details for Product Number: " + ProductID Alignment = Center
    Font Style = Bold
    Font Size = 12pt
  2. Add the following labels to the detail section, setting their properties as indicated:

    ShowrptProductDetails labels

    Location Size Text Miscellaneous
    0, 0 in 1, 0.198 in Product Name Font Style = Bold
    0, 0.28 in 1, 0.198 in Supplier Font Style = Bold
    0, 0.54 in 1, 0.198 in Qty per Unit Font Style = Bold
    0, 0.83 in 1, 0.198 in Units in Stock Font Style = Bold
    0, 1.12 in 1, 0.198 in Reorder Level Font Style = Bold
    4.4, 0 in 1, 0.198 in Category Font Style = Bold
    4.4, 0.28 in 1, 0.198 in Discontinued Font Style = Bold
    4.4, 0.54 in 1, 0.198 in Unit Price Font Style = Bold
    4.4, 0.83 in 1, 0.198 in Units Pending Font Style = Bold
  3. From the Report Explorer, drag the following fields onto the detail section, setting their properties as indicated:

    ShowrptProductDetails fields

    Field Location Size Miscellaneous
    ProductName 1.14, 0 in 2.05, 0.2 in
    CompanyName 1.14, 0.28 in 2.05, 0.2 in
    QuantityPerUnit 1.14, 0.54 in 2.28, 0.2 in
    UnitsInStock 1.14, 0.83 in 1, 0.2 in
    ReorderLevel 1.14, 1.12 in 1, 0.2 in
    CategoryName 5.5, 0 in 1, 0.2 in
    Discontinued 5.5, 0.28 in 1, 0.2 in
    UnitPrice 5.5, 0.54 in 1, 0.2 in OutputFormat = $#,##0.00
    UnitsOnOrder 5.5, 0.83 in 1, 0.2 in
    TextBox Location Size Miscellaneous
    ="Return to Orders for " + OrderID 4.4, 1.125 in 2.1, 0.2 in (Name) = txtReturnToOrders

To add code to the viewer form for special hyperlink functions

This walkthrough assumes that you already know how to display a report in the viewer. For more information about these basic functions, see the Viewing Reports topic.

ShowTo write the code in Visual Basic

  1. Right-click the form with the ActiveReports viewer and select View Code.
  2. At the top left of the code window, click the drop-down arrow and select Viewer1.
  3. At the top right of the code window, click the drop-down arrow and select Hyperlink. This creates an event-handling method for the form's Viewer1_Hyperlink event.
  4. Add a method to clear the viewer and dispose of the report document.
  5. Add code to the handler to process hyperlink text, determine which report to run, and display the report.

The following example shows what the code for the method looks like.

Visual Basic.NET code. Paste JUST ABOVE the Viewer HyperLink event. Copy Code
Private LastCustID As String
Visual Basic.NET code. Paste JUST BELOW the Viewer HyperLink event. Copy Code
Private Sub ClearViewer() 
    Dim doc As DataDynamics.ActiveReports.Document.Document = viewer1.Document 
    viewer1.Document = Nothing 
    viewer1.Refresh() 
    doc.Dispose() 
    doc = Nothing 
End Sub
Visual Basic.NET code. Paste INSIDE the Viewer HyperLink event. Copy Code
'Process hyperlink text.
Dim report, parameter As String

If e.HyperLink.IndexOf("\") > 0 And e.HyperLink.Length > 2 Then
    report = e.HyperLink.Substring(0, e.HyperLink.IndexOf("\")).ToUpper()
    parameter = e.HyperLink.Substring(e.HyperLink.IndexOf("\") + 1)
Else
    MessageBox.Show("Cannot process hyperlink.")
    Return
End If

Dim rpt As DataDynamics.ActiveReports.ActiveReport = Nothing

'Determine which report to run.
If report.CompareTo("CUSTOMERS") = 0 Then
    rpt = New rptCustomers()
ElseIf report.CompareTo("ORDERS") = 0 Then
    rpt = New rptOrders()
    rpt.Parameters("CustomerID").Value = parameter
    LastCustID = parameter
ElseIf report.CompareTo("PRODUCTS") = 0 Then
    rpt = New rptProductDetails(LastCustID)
    rpt.Parameters("ProductID").Value = parameter
Else
    MessageBox.Show("Invalid report ID")
End If

'Check whether a report object exists. If so, run and display it.
If rpt IsNot Nothing Then
    ClearViewer()
    rpt.ShowParameterUI = False
    Viewer1.Document = rpt.Document
    rpt.Run()
    rpt.Dispose()
    rpt = Nothing
End If

ShowTo write the code in C#

  1. Click the Viewer to select the it.
  2. Click the events icon in the Properties Window to display available events for the viewer.
  3. Double-click Hyperlink. This creates an event-handling method for the form's viewer1_Hyperlink event.
  4. Add a method to clear the viewer and dispose of the report document.
  5. Add code to the handler to process hyperlink text, determine which report to run, and display the report.

The following example shows what the code for the method looks like.

C# code. Paste JUST ABOVE the viewer HyperLink event. Copy Code
private string LastCustID;
C# code. Paste JUST BELOW the viewer HyperLink event. Copy Code
private void ClearViewer()
{
    DataDynamics.ActiveReports.Document.Document doc = viewer1.Document;

    viewer1.Document = null;
    viewer1.Refresh();

    doc.Dispose();
    doc = null;
}
C# code. Paste INSIDE the viewer HyperLink event. Copy Code
//Process hyperlink text.
string report, parameter;

if (e.HyperLink.IndexOf('\\') > 0 && e.HyperLink.Length > 2)
{
    report = e.HyperLink.Substring(0, e.HyperLink.IndexOf('\\')).ToUpper();
    parameter = e.HyperLink.Substring(e.HyperLink.IndexOf('\\') + 1);
}
else
{
    MessageBox.Show("Cannot process hyperlink.");
    return;
}

DataDynamics.ActiveReports.ActiveReport rpt = null;

//Determine which report to run.
if (report.CompareTo("CUSTOMERS") == 0)
{
    rpt = new rptCustomers();
}
else if (report.CompareTo("ORDERS") == 0)
{
    rpt = new rptOrders();
    rpt.Parameters["CustomerID"].Value = parameter;
    LastCustID = parameter;
}
else if (report.CompareTo("PRODUCTS") == 0)
{
    rpt = new rptProductDetails(LastCustID);
    rpt.Parameters["ProductID"].Value = parameter;
}
else
{
    MessageBox.Show("Invalid report ID");
}

//Check whether a report object exists. If so, run and display it.
if (rpt != null)
{
    ClearViewer();
    rpt.ShowParameterUI = false;
    viewer1.Document = rpt.Document;
    rpt.Run();
    rpt.Dispose();
    rpt = null;
}

To add code to set the drill-down hyperlink in rptCustomers

  1. Double-click in the detail section to create a detail_Format event.
  2. Add code to the event to set the hyperlink of the Customer ID textbox to call the viewer code that passes the parameter to rptOrders.

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Format event. Copy Code
txtCustomerID1.HyperLink = "Orders\" + txtCustomerID1.Text

ShowTo write the code in C#

C# code. Paste INSIDE the Format event. Copy Code
txtCustomerID1.HyperLink = "Orders\\" + txtCustomerID1.Text;

To add code to set the drill-down hyperlink in rptOrders

  1. Double-click in the detail section to create a detail_Format event.
  2. Add code to the event to set the hyperlink of the Product ID textbox to call the viewer code that passes the parameter to rptProductDetails.

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Format event. Copy Code
txtProductID1.HyperLink = "Products\" + txtProductID1.Text

ShowTo write the code in C#

C# code. Paste INSIDE the Format event. Copy Code
txtProductID1.HyperLink = "Products\\" + txtProductID1.Text;

To add code to create a parameter to hold the previous report for rptProductDetails

  1. Right-click the report and select View Code.
  2. Add code to create a parameter for the previous report.

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste JUST BELOW the Public Class rptProductDetails line. Copy Code
'The prevRptParam member is used to track the parameter for 
'returning to the orders report for the correct customer 
Private prevRptParam As String
Public Sub New(ByVal previousRptParameter As String)
    InitializeComponent()
    prevRptParam = previousRptParameter
End Sub

ShowTo write the code in C#

C# code. Paste JUST BELOW the public partial class rptProductDetails() line. Copy Code
//The prevRptParam member is used to track the parameter for
        //returning to the orders report for the correct customer
        private string prevRptParam;

        public rptProductDetails(string previousRptParameter)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
            prevRptParam = previousRptParameter;

        }
C# code. Paste INSIDE the parentheses in the public rptProductDetails() line. Copy Code
string previousRptParameter

To add code to set the hyperlink to return to rptOrders in rptProductDetails

  1. Double-click in the detail section to create a detail_Format event.
  2. Add code to the event to set the hyperlink of the Return to Orders textbox to call the code that passes the parameter to rptProductDetails.

ShowTo write the code in Visual Basic.NET

Visual Basic.NET code. Paste INSIDE the Format event. Copy Code
Me.txtReturnToOrders.Text = Me.txtReturnToOrders.Text + prevRptParam
Me.txtReturnToOrders.HyperLink = "Orders\" + prevRptParam

ShowTo write the code in C#

C# code. Paste INSIDE the Format event. Copy Code
this.txtReturnToOrders.Text = this.txtReturnToOrders.Text + prevRptParam;
this.txtReturnToOrders.HyperLink = "Orders\\" + prevRptParam;

See Also