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 イベント ハンドラーを提供します。
ドリルスルー レポートのデータを読み込むには、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