ReportViewer.Drillthrough 事件

 

發生在於報表中選取鑽研項目時。

命名空間:   Microsoft.Reporting.WinForms
組件:  Microsoft.ReportViewer.WinForms (在 Microsoft.ReportViewer.WinForms.dll 中)

語法

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

備註

這個事件發生在於報表中選取鑽研項目時。這個事件的相關資訊會在 T:Microsoft.Reporting.WinForms.DrillThroughEventArgs 物件中傳遞至 T:Microsoft.Reporting.WinForms.DrillThroughEventHandler 委派,由它來處理事件。

如果鑽研報表有子報表,您必須提供這些子報表的資料。若要執行這個動作,請將 SubreportProcessing 事件處理常式提供給透過 T:Microsoft.ReportingServices.DrillthroughEventArgs 物件來傳遞的鑽研報表。

若要載入鑽研報表的資料,您必須呼叫透過 T:Microsoft.Reporting.WinForms.DrillThroughEventArgs 物件 (而不是 ReportViewer 控制項所用的 LocalReport 物件) 來傳遞之鑽研報表的 DataSources.Add 方法。

加入鑽研事件處理常式方法的資料來源名稱,必須符合鑽研報表指定的資料來源名稱。您可以在 [報表設計工具] 中,按一下 [報表] 功能表,選取 [資料來源] 來檢視這個資料來源的名。這會開啟 [報表資料來源] 對話方塊來顯示報表所定義之報表資料來源的名稱。

如需處理事件的詳細資訊,請參閱NIB: 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 命名空間

回到頁首