LocalReport.SubreportProcessing 事件

在处理子报表时发生。

命名空间:  Microsoft.Reporting.WinForms
程序集:  Microsoft.ReportViewer.WinForms(在 Microsoft.ReportViewer.WinForms.dll 中)

语法

声明
Public Event SubreportProcessing As SubreportProcessingEventHandler
用法
Dim instance As LocalReport
Dim handler As SubreportProcessingEventHandler

AddHandler instance.SubreportProcessing, handler
public event SubreportProcessingEventHandler SubreportProcessing
public:
 event SubreportProcessingEventHandler^ SubreportProcessing {
    void add (SubreportProcessingEventHandler^ value);
    void remove (SubreportProcessingEventHandler^ value);
}
member SubreportProcessing : IEvent<SubreportProcessingEventHandler,
    SubreportProcessingEventArgs>
JScript 支持使用事件,但不支持声明新事件。

注释

SubreportProcessing 事件是针对主报表中子报表的每个实例触发的,而不是针对每个子报表定义触发的。如果报表包含同一报表定义中的多个子报表实例,则可以针对每个实例触发此事件。

您必须为子报表中使用的所有数据源提供数据。为此,您必须为 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 类

Microsoft.Reporting.WinForms 命名空间