ReportViewer.Drillthrough 事件

在报表中选择了钻取项时发生。

命名空间:  Microsoft.Reporting.WinForms
程序集:  Microsoft.ReportViewer.WinForms(在 Microsoft.ReportViewer.WinForms.dll 中)

语法

声明
Public Event Drillthrough As DrillthroughEventHandler
用法
Dim instance As ReportViewer
Dim handler As DrillthroughEventHandler

AddHandler instance.Drillthrough, handler
public event DrillthroughEventHandler Drillthrough
public:
 event DrillthroughEventHandler^ Drillthrough {
    void add (DrillthroughEventHandler^ value);
    void remove (DrillthroughEventHandler^ value);
}
member Drillthrough : IEvent<DrillthroughEventHandler,
    DrillthroughEventArgs>
JScript 支持使用事件,但不支持声明新事件。

注释

在报表中选择了钻取项时发生此事件。有关此事件的信息通过 DrillThroughEventArgs 对象传递到处理此事件的 DrillThroughEventHandler 委托。

如果钻取报表有子报表,您必须为那些子报表提供数据。为此,请为通过 DrillthroughEventArgs 对象传递的钻取报表提供 SubreportProcessing 事件处理程序。

若要为钻取报表加载数据,您必须对通过 DrillThroughEventArgs 对象(而不是通过 ReportViewer 控件使用的 LocalReport 对象)传递的钻取报表调用 DataSources.Add 方法。

在钻取事件处理程序方法中添加的数据源的名称必须与在钻取报表中指定的数据源名称相匹配。可以在报表设计器中通过单击**“报表”菜单并选择“数据源”来查看此数据源的名称。这会打开“报表数据源”**对话框,其中显示了在报表中定义的报表数据源的名称。

有关处理事件的更多信息,请参见Consuming Events

示例

以下示例代码加载包含一组钻取项的示例报表,并设置事件处理程序来处理钻取事件。传递到钻取事件处理程序的参数包括钻取报表对象。在 ReportViewer 控件中呈现钻取报表之前,事件处理程序会先向此报表添加数据源。

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;
    }
}

下面的 Visual Basic 示例假定您已创建了包含窗体和 ReportViewer 控件的 Windows 应用程序。

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

请参阅

参考

ReportViewer 类

Microsoft.Reporting.WinForms 命名空间