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);
}
/** @event */
public void add_Drillthrough (DrillthroughEventHandler value)

/** @event */
public void remove_Drillthrough (DrillthroughEventHandler value)
JScript supports the use of events, but not the declaration of new ones.

解説

このイベントは、レポートでドリルスルー アイテムが選択されたときに発生します。このイベントに関する情報は、DrillThroughEventArgs オブジェクトによって、イベントを処理する DrillThroughEventHandler デリゲートに渡されます。

ドリルスルー レポートにサブレポートが含まれている場合は、サブレポートのデータを指定する必要があります。これを行うには、DrillthroughEventArgs オブジェクトを通じて渡されるドリルスルー レポートに SubreportProcessing イベント ハンドラを提供します。

ドリルスルー レポートのデータを読み込むには、ReportViwer コントロールで使用する 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

''Set RDL file.

ReportViewer1.LocalReport.ReportPath = "c:\My Reports\Departments.rdlc"

'' Supply a DataTable corresponding to each report data source.

Dim myReportDataSource = New ReportDataSource("Departments", LoadDepartmentsData())

ReportViewer1.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 クラス
ReportViewer メンバ
Microsoft.Reporting.WinForms 名前空間