本文為機器翻譯文章。如需檢視英文版,請選取 [原文] 核取方塊。您也可以將滑鼠指標移到文字上,即可在快顯視窗顯示英文原文。
譯文
原文

LocalReport.SubreportProcessing 事件

 

發佈時間: 2016年4月

發生在處理子報表時。

命名空間:   Microsoft.Reporting.WinForms
組件:  Microsoft.ReportViewer.WinForms (在 Microsoft.ReportViewer.WinForms.dll 中)

public event SubreportProcessingEventHandler SubreportProcessing

The SubreportProcessing event is triggered for every instance of the subreport in the main report, and not just for each subreport definition. If a report contains multiple subreports instances from the same report definition, this event is triggered for each instance.

You must supply data for any data sources used in subreports. To do this, you must supply an event handler for the SubreportProcessing event.

You can examine values of parameters passed to the subreport by examining the Parameters property and supplying data corresponding to those parameter values.

If the main report has several subreports, you can examine the ReportPath property of the SubreportProcessingEventArgs class to determine which subreport is being processed and supply data for that subreport.

For more information about the arguments passed to this event handler, see SubreportProcessingEventArgs.

The following code example implements a master/detail report using subreports. The code loads a sample report that contains a subreport and sets up an event handler to handle the SubreportProcessing event. The arguments passed to the SubreportProcessing event handler include an object encapsulating the subreport. The event handler adds a data source instance to this subreport before it is rendered in the ReportViewer control.

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;
    }
}
回到頁首
顯示: