Freigeben über


ReportViewer.Drillthrough-Ereignis

Occurs when a drillthrough item is selected in a report.

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

Syntax

Hinweise

This event occurs when a drillthrough item is selected in a report. Information about this event is passed in a DrillThroughEventArgs object to the 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 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 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 Behandeln von Ereignissen.

Beispiel

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();
        dataSet.ReadXml(@"c:\employees.xml");
        return dataSet.Tables[0];
    }

    private DataTable LoadDepartmentsData()
    {
        DataSet dataSet = new DataSet();
        dataSet.ReadXml(@"c:\departments.xml");
        return dataSet.Tables[0];
    }

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

    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.
        reportViewer.LocalReport.DataSources.Add(
            new ReportDataSource("Departments", 
            LoadDepartmentsData()));

        // Add a handler for drillthrough.
        reportViewer.Drillthrough += new 
            DrillthroughEventHandler(DemoDrillthroughEventHandler);

        // Add the reportviewer to the form.
        reportViewer.Dock = DockStyle.Fill;
        this.Controls.Add(reportViewer);

        // Process and render the report.
        reportViewer.RefreshReport();
    }

    [STAThread]
    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())
        localReport.DataSources.Add(myReportDataSource)

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

        '' Process and render the report. 
        Me.ReportViewer1.RefreshReport()

    End Sub
End Class

Siehe auch

Verweis

ReportViewer-Klasse
ReportViewer-Member
Microsoft.Reporting.WinForms-Namespace