Skip to main content
A newer version of this page is available. .

Create Drill-Through Reports

  • 4 minutes to read

This tutorial describes the steps to create a drill-through report, in which the detail report for a chosen category can be invoked in a new window by a click, allowing you to avoid redundant information in the original report.

Tip

This example targets the Windows Forms platform and is available online at How to create a drill-through report.

See the following examples to learn how to implement the drill-through functionality in WPF and ASP.NET:

To create a drill-through report, do the following.

  1. Create a new application or open an existing application.

  2. Add a new blank report to it (named MasterReport), and bind the report to the “Categories” table of the sample Northwind database (nwind.mdb file, shipped with the XtraReports installation, the default path is C:\Users\Public\Public Documents\DevExpress Demos 20.2\Components\Data\nwind.mdb).
  3. From the Field List, drop the CategoryName data field onto the report’s Detail band, to automatically create a data-bound control.

    HowTo - DrillThroughReport_0

  4. Add another blank report (named DetailReport), and bind it to the “Products” table of the Northwind database.
  5. To add a parameter to the report, in the Field List, right-click the Parameters section and choose Add Parameter.

    Shared_FieldList_AddParameter

  6. In this way, create two parameters, named catId and catName. For the catId parameter set the Parameter.Type property to Number (32 bit integer).

    HowTo - DrillThroughReport_2

  7. Now, create a ReportHeaderBand

    Shared_BandsAddReportHeader

    And, from the Field List, drop the catName parameter onto the created band.

    HowTo - DrillThroughReport_2a

  8. Then, add a GroupHeaderBand to the report. And, create a table report representing data from the “Products” data table.

    Finally, the DetailReport should look as shown in the following image.

    HowTo - DrillThroughReport_3

  9. Now, set the report’s XtraReport.RequestParameters property to false, and for the XtraReportBase.FilterString property, click the ellipsis button, to invoke the FilterString Editor.

    HowTo - DrillThroughReport_4

  10. Using this editor, define the following expression: [CategoryID] = ?catId.

    HowTo - DrillThroughReport_5

  11. Now, switch back to the MasterReport, and for the created label control, handle the following events: XRControl.BeforePrint, XRControl.PreviewClick and XRControl.PreviewMouseMove.

    HowTo - DrillThroughReport_6

  12. The following code should be applied to these event handlers.

    Note that the control’s XRControl.Tag property is used to store the current row object.

    using DevExpress.DataAccess.Sql.DataApi;
    using DevExpress.XtraReports.UI;
    using System.Drawing.Printing;
    using System.Windows.Forms;
    // ...
    
    // Save the data for the current category to the label's Tag property.
    private void xrLabel1_BeforePrint(object sender, PrintEventArgs e) {
        ((XRLabel)sender).Tag = GetCurrentRow();
    }
    
    private void xrLabel1_PreviewClick(object sender, PreviewMouseEventArgs e) {
        // Create a new Detail Report instance.
        DetailReport detailReport = new DetailReport();
    
        // Obtain the current category's ID and Name from the e.Brick.Value property,
        // which stores an object assigned to the label's Tag property.
        IRow row = (IRow)e.Brick.Value;
        // Obtain the current category's ID and Name from the row object.
        detailReport.Parameters["catId"].Value = row["CategoryID"];
        detailReport.Parameters["catName"].Value = row["CategoryName"]; 
    
        // Show the detail report in a new modal window.
        ReportPrintTool pt = new ReportPrintTool(detailReport);
        pt.ShowPreviewDialog();
    }
    
    // The following code changes the cursor to "hand" when it hovers the label, 
    // so that it behaves as a common link.
    private void xrLabel1_PreviewMouseMove(object sender, PreviewMouseEventArgs e) {
        e.PreviewControl.Cursor = Cursors.Hand;
    }
    

The drill-through report is now ready. Run the print preview form, and view the result.

HowTo - DrillThroughReport_7

See Also