xtrareports-4789-feature-guide-to-devexpress-reports-provide-interactivity-create-drill-through-reports.md
Follow this tutorial to create a drill-through report where a user can click a “Category Name” entry to invoke a detail report that contains Products within that category. This report type keeps the original report compact while allowing access to more detailed information.
The tutorial involves two main steps:
Run Demo: WinForms Run Demo: WPF Run Demo: ASP.NET Core Run Demo: Blazor
To complete the tutorial, you need two reports in which you can define a master-detail relationship.
This tutorial uses XtraReportCategories and XtraReportProducts reports based on the Categories and Products tables from the Sample Northwind SQLite Database (nwind.db).
You can download one of the following examples to try out this functionality or use the example’s reports for this tutorial:
View Example: WinForms View Example: WPF View Example: ASP.NET Core
Define a master-detail relationship between Category and Product reports within a single project:
If you switch to Preview , you can click on a Category value in the table. The Preview window navigates to the detail report that contains all Product entries. The next step explains how to filter this list.
A Breadcrumb control automatically appears below the Document Viewer toolbar and allows you to navigate back to the original report.
You can specify parameters during detail report navigation. Use the NavigateToReportAction.ParameterBindings property to limit displayed records (such as products) to a selected category.
To invoke the Parameter Binding Collection Editor , click the ellipsis button in the Parameter Bindings property. Within this editor, click the Sync button to automatically obtain detail report parameters and set Binding to the original report’s data field or parameter.
Set Binding to the CategoryID field.
Set the following filter string in the detail report to display product records for the selected category.
Switch to Preview and click on a category entry in the master report. The Preview navigates to the detail report that displays only products related to the selected category.
The following code snippet shows the same scenario in code:
using DevExpress.XtraReports.Interactivity;
using DevExpress.XtraReports.UI;
namespace Drill_through_example {
public partial class XtraReportCategories : DevExpress.XtraReports.UI.XtraReport {
public XtraReportCategories(){
InitializeComponent();
// Create a NavigateToReportAction instance and specify its settings
NavigateToReportAction cellAction = new NavigateToReportAction();
cellAction.ReportSource = new XtraReportProducts();
cellAction.ParameterBindings.Add(new ParameterBinding(parameterName: "categoryId",
sqlDataSource1, "Categories.CategoryID"));
// Assign the NavigateToReportAction object to the control’s Action property
tableCell6.Action = cellAction;
}
}
public partial class XtraReportProducts : DevExpress.XtraReports.UI.XtraReport {
public XtraReportProducts(){
InitializeComponent();
FilterString = "[CategoryID] = ?categoryId";
}
}
}
Imports DevExpress.XtraReports.Interactivity
Imports DevExpress.XtraReports.UI
Namespace Drill_through_example
Partial Public Class XtraReportCategories
Inherits DevExpress.XtraReports.UI.XtraReport
Public Sub New()
InitializeComponent()
' Create a NavigateToReportAction instance and specify its settings
Dim cellAction As New NavigateToReportAction()
cellAction.ReportSource = New XtraReportProducts()
cellAction.ParameterBindings.Add(New ParameterBinding(parameterName:= "categoryId", sqlDataSource1, "Categories.CategoryID"))
' Assign the NavigateToReportAction object to the control’s Action property
tableCell6.Action = cellAction
End Sub
End Class
Partial Public Class XtraReportProducts
Inherits DevExpress.XtraReports.UI.XtraReport
Public Sub New()
InitializeComponent()
FilterString = "[CategoryID] = ?categoryId"
End Sub
End Class
End Namespace
See Also