Create Drill-Through Reports

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. Start Microsoft Visual Studio 2010, 2012, 2013, 2015 or 2017 and create a new application under any of the supported platforms, or open an existing one.
  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).
  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] = [Parameters.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 data field's value.

    using System.Data;
    using System.Windows.Forms;
    using System.Drawing.Printing;
    using DevExpress.XtraReports.UI;
    // ...
    
    // 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 the label's Tag property.
        detailReport.catId.Value = (int)((DataRowView)e.Brick.Value).Row["CategoryID"];
        detailReport.catName.Value = ((DataRowView)e.Brick.Value).Row["CategoryName"].ToString();
    
        // 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