Condividi tramite


Evento LocalReport.SubreportProcessing

Viene generato durante l'elaborazione di un sottoreport.

Spazio dei nomi: Microsoft.Reporting.WinForms
Assembly: Microsoft.ReportViewer.WinForms (in microsoft.reportviewer.winforms.dll)

Sintassi

'Dichiarazione
<SRDescriptionAttribute("SubreportProcessingEventDesc")> _
Public Event SubreportProcessing As SubreportProcessingEventHandler
'Utilizzo
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.

Note

È necessario specificare i dati relativi a tutte le origini dei dati utilizzate nei sottoreport. A tale scopo, occorre specificare un gestore dell'evento per l'evento SubreportProcessing.

È possibile esaminare i valori dei parametri passati al sottoreport analizzando la proprietà Parameters e specificando i dati corrispondenti a tali valori.

Se nel report principale sono presenti più sottoreport, è possibile esaminare la proprietà ReportPath della classe SubreportProcessingEventArgs per determinare il sottoreport in corso di elaborazione e specificare i dati a esso relativi.

Per una descrizione degli argomenti passati a questo gestore dell'evento, vedere SubreportProcessingEventArgs.

Esempio

Nell'esempio di codice seguente viene implementato un report master-dettagli mediante l'utilizzo di sottoreport. Il codice consente di caricare un report di esempio, che contiene un sottoreport, e di impostare un gestore dell'evento per la gestione dell'evento SubreportProcessing. Gli argomenti passati al gestore dell'evento SubreportProcessing includono un oggetto che incapsula il sottoreport. Il gestore dell'evento aggiunge un'istanza dell'origine dei dati al sottoreport prima che ne venga eseguito il rendering nel controllo 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

Vedere anche

Riferimento

Classe LocalReport
Membri LocalReport
Spazio dei nomi Microsoft.Reporting.WinForms