다음을 통해 공유


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는 이벤트 사용을 지원하지만 새로운 이벤트 선언은 지원하지 않습니다.

주의

이 이벤트는 보고서에서 드릴스루 항목이 선택될 때 발생합니다. 이 이벤트에 대한 정보는 이벤트를 처리하는 DrillThroughEventHandler 대리자에게 DrillThroughEventArgs 개체를 통해 전달됩니다.

드릴스루 보고서에 포함된 보고서가 있을 경우 이러한 포함된 보고서에 대한 데이터를 제공해야 합니다. 이렇게 하려면 DrillthroughEventArgs 개체를 통해 전달되는 드릴스루 보고서에 SubreportProcessing 이벤트 처리기를 제공합니다.

드릴스루 보고서에 대한 데이터를 로드하려면 ReportViewer 컨트롤에서 사용하는 LocalReport 개체가 아닌 DrillThroughEventArgs 개체를 통해 전달되는 드릴스루 보고서의 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 네임스페이스