ReportViewer.Drillthrough Event


Occurs when a drillthrough item is selected in a report.

Namespace:   Microsoft.Reporting.WinForms
Assembly:  Microsoft.ReportViewer.WinForms (in Microsoft.ReportViewer.WinForms.dll)


public event DrillthroughEventHandler Drillthrough
event DrillthroughEventHandler^ Drillthrough {
    void add(DrillthroughEventHandler^ value);
    void remove(DrillthroughEventHandler^ value);
member Drillthrough : IEvent<DrillthroughEventHandler,
Public Event Drillthrough As DrillthroughEventHandler


This event occurs when a drillthrough item is selected in a report. Information about this event is passed in a T:Microsoft.Reporting.WinForms.DrillThroughEventArgs object to the T:Microsoft.Reporting.WinForms.DrillThroughEventHandler delegate, which handles the event.

If the drillthrough report has subreports, you must supply data for those subreports. To do this, provide a SubreportProcessing event handler to the drillthrough report that is passed via the T:Microsoft.ReportingServices.DrillthroughEventArgs object.

To load data for the drillthrough report, you must call the DataSources.Add method of the drillthrough report that is passed via the T:Microsoft.Reporting.WinForms.DrillThroughEventArgs object, rather than the LocalReport object used by the ReportViewer control.

The name of the data source added in the drillthrough event handler method must match the data source name that was specified in the drillthrough report. The name of this data source can be viewed in the Report Designer by clicking the Report menu and selecting Data Sources. This opens the Report Data Sources dialog box that displays the names of the report data sources defined in the report.

For more information about handling events, see NIB: Consuming Events.


Legacy Code Example

The following sample code loads a sample report containing a series of drillthrough items and sets up an event handler to handle the drillthrough events. The arguments passed to the drillthrough event handler include a drillthrough report object. The event handler adds a data source to this report before the drillthrough report is rendered in the ReportViewer control.

using System;
using System.Data;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

public class Demo : Form
    private DataTable LoadEmployeesData()
        DataSet dataSet = new DataSet();
        return dataSet.Tables[0];

    private DataTable LoadDepartmentsData()
        DataSet dataSet = new DataSet();
        return dataSet.Tables[0];

    void DemoDrillthroughEventHandler(object sender, 
        DrillthroughEventArgs e)
        LocalReport localReport = (LocalReport)e.Report;
        localReport.DataSources.Add(new ReportDataSource("Employees",

    public Demo()
        this.Text = "Report Control Demo";
        this.ClientSize = new System.Drawing.Size(950, 600);

        ReportViewer reportViewer = new ReportViewer();

        // Set Processing Mode.
        reportViewer.ProcessingMode = ProcessingMode.Local;

        // Set RDL file.
        reportViewer.LocalReport.ReportPath = @"c:\Departments.rdlc";

        // Supply a DataTable corresponding to each report 
        // data source.
            new ReportDataSource("Departments", 

        // Add a handler for drillthrough.
        reportViewer.Drillthrough += new 

        // Add the reportviewer to the form.
        reportViewer.Dock = DockStyle.Fill;

        // Process and render the report.

    public static int Main(string[] args)
        Application.Run(new Demo());
        return 0;

The Visual Basic sample below assumes that you have created a Windows application with a form and a ReportViewer control.

Imports System.Data
Imports Microsoft.Reporting.WinForms

Public Class Form1

    Private Function LoadEmployeesData() As DataTable
        Dim dataSet As New DataSet()
        dataSet.ReadXml("c:\My Reports\employees.xml")
        LoadEmployeesData = dataSet.Tables(0)
    End Function

    Private Function LoadDepartmentsData()
        Dim dataSet As New DataSet()
        dataSet.ReadXml("c:\My Reports\departments.xml")
        LoadDepartmentsData = dataSet.Tables(0)
    End Function

    Public Sub DemoDrillthroughEventHandler(ByVal sender As Object, _
        ByVal e As DrillthroughEventArgs)
        Dim localReport = e.Report
        localReport.DataSources.Add(New ReportDataSource( _
            "Employees", LoadEmployeesData()))
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load

        ReportViewer1.ProcessingMode = ProcessingMode.Local

        Dim localReport = ReportViewer1.LocalReport

        ''Set RDL file. 
        localReport.ReportPath = "c:\My Reports\Departments.rdlc"

        '' Supply a DataTable corresponding to each report 
        '' data source. 
        Dim myReportDataSource = New ReportDataSource( _
            "Departments", LoadDepartmentsData())

        ''Add a handler for drillthrough. 
        AddHandler ReportViewer1.Drillthrough, _
            AddressOf DemoDrillthroughEventHandler

        '' Process and render the report. 

    End Sub
End Class

See Also

ReportViewer Class
Microsoft.Reporting.WinForms Namespace

Return to top