LocalReport.SubreportProcessing イベント

サブレポートが処理されるときに発生します。

名前空間: Microsoft.Reporting.WinForms
アセンブリ: Microsoft.ReportViewer.WinForms (microsoft.reportviewer.winforms.dll 内)

構文

'宣言
'使用

解説

サブレポートで使用するデータ ソースにデータを指定する必要があります。それには、SubreportProcessing イベントのイベント ハンドラを指定してください。

Parameters プロパティを確認して、サブレポートに渡されたパラメータの値を調べると、それらのパラメータ値に対応するデータを指定できます。

メイン レポートに複数のサブレポートがある場合は、SubreportProcessingEventArgs クラスの ReportPath プロパティを調べて、どのサブレポートが処理されているかを判断し、そのサブレポートのデータを指定します。

このイベント ハンドラに渡される引数については、「SubreportProcessingEventArgs」を参照してください。

次のサンプル コートでは、サブレポートを使用してマスタ詳細レポートを実装します。このコードでは、サブレポートを含んでいるサンプル レポートを読み込んで、SubreportProcessing イベントを処理するイベント ハンドラを設定します。SubreportProcessing イベント ハンドラに渡される引数には、サブレポートをカプセル化しているオブジェクトが含まれています。イベント ハンドラによって、このサブレポートにデータ ソースのインスタンスが追加されてから、ReportViewer コントロールで表示されます。

using System;
using System.Data;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;

public class Demo : Form
{
    private DataTable orderDetailsData = null;

    private DataTable LoadOrdersData()
    {
        // Load data from XML file.
        DataSet dataSet = new DataSet();
        dataSet.ReadXml(@"c:\OrderData.xml");
        return dataSet.Tables[0];
    }

    private DataTable LoadOrderDetailsData()
    {
        // Load data from XML file.
        DataSet dataSet = new DataSet();
        dataSet.ReadXml(@"c:\OrderDetailData.xml");
        return dataSet.Tables[0];
    }

    void DemoSubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
    {
        if (orderDetailsData == null)
            orderDetailsData = LoadOrderDetailsData();
        e.DataSources.Add(new ReportDataSource("DataSet1_OrderDetails", orderDetailsData));
    }

    public Demo()
    {
        this.Text = "Report Control Demo";
        this.ClientSize = new System.Drawing.Size(700, 600);

        ReportViewer reportViewer = new ReportViewer();

        // Set Processing Mode.

        reportViewer.ProcessingMode = ProcessingMode.Local;

        // Set RDL file.

        reportViewer.LocalReport.ReportPath = @"c:\Orders.rdlc";

        // Add a handler for SubreportProcessing.

        reportViewer.LocalReport.SubreportProcessing +=
                    new SubreportProcessingEventHandler(DemoSubreportProcessingEventHandler);

        // Supply a DataTable corresponding to each report dataset.

        reportViewer.LocalReport.DataSources.Add(
            new ReportDataSource("DataSet1_Orders", LoadOrdersData()));

        // 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;
    }
}
Option Explicit On
Imports System
Imports System.Drawing
Imports Microsoft.Reporting.WinForms

Public Class Form1
    Inherits System.Windows.Forms.Form

    Private orderDetailsData As DataTable = Nothing
    Friend WithEvents ReportViewer1 As Microsoft.Reporting.WinForms.ReportViewer

    Function LoadOrdersData() As DataTable
        ' Load
        Dim dataSet As New DataSet()
        dataSet.ReadXml("c:\MyReports\OrderData.xml")
        Return dataSet.Tables(0)

    End Function

    Function LoadOrderDetailsData() As DataTable
        Dim dataSet As New DataSet()
        dataSet.ReadXml("c:\MyReports\OrderDetailData.xml")
        Return dataSet.Tables(0)
    End Function

    Public Sub DemoSubreportProcessingEventHandler(ByVal sender As Object, _
     ByVal e As SubreportProcessingEventArgs)

        If orderDetailsData Is Nothing Then
            orderDetailsData = LoadOrderDetailsData()
        End If
        e.DataSources.Add(New ReportDataSource("DataSet1_OrderDetails", orderDetailsData))
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Me.ReportViewer1 = New Microsoft.Reporting.WinForms.ReportViewer
        Me.ReportViewer1.Dock = System.Windows.Forms.DockStyle.Fill

        Me.Text = "Report Control Demo"
        Me.ClientSize = New System.Drawing.Size(700, 600)
        Me.ReportViewer1.ProcessingMode = ProcessingMode.Local
        Me.ReportViewer1.LocalReport.ReportPath = "c:\MyReports\Orders.rdlc"
        AddHandler Me.ReportViewer1.LocalReport.SubreportProcessing, AddressOf DemoSubreportProcessingEventHandler
        Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1_Orders", LoadOrdersData()))
        Me.Controls.Add(ReportViewer1)
        Me.ReportViewer1.RefreshReport()

    End Sub

End Class

参照

リファレンス

LocalReport クラス
LocalReport メンバ
Microsoft.Reporting.WinForms 名前空間