LocalReport.SubreportProcessing 事件
發生在處理子報表時。
命名空間: Microsoft.Reporting.WinForms
組件: Microsoft.ReportViewer.WinForms (在 microsoft.reportviewer.winforms.dll)
語法
'宣告
<SRDescriptionAttribute("SubreportProcessingEventDesc")> _
Public Event SubreportProcessing As SubreportProcessingEventHandler
'用途
Dim instance As LocalReport
Dim handler As SubreportProcessingEventHandler
AddHandler instance.SubreportProcessing, handler
[SRDescriptionAttribute("SubreportProcessingEventDesc")]
public event SubreportProcessingEventHandler SubreportProcessing
public:
event SubreportProcessingEventHandler^ SubreportProcessing {
void add (SubreportProcessingEventHandler^ value);
void remove (SubreportProcessingEventHandler^ value);
}
/** @event */
public void add_SubreportProcessing (SubreportProcessingEventHandler value)
/** @event */
public void remove_SubreportProcessing (SubreportProcessingEventHandler value)
JScript supports the use of events, but not the declaration of new ones.
備註
您必須提供子報表所用之任何資料來源的資料。若要這麼做,您必須提供 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 命名空間