A newer version of this page is available. Switch to the current version.

XtraReport.SaveComponents Event

Occurs when a report is saved to an REPX file and allows you to manually decide which components should be stored into a report definition file, and which aren't.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v18.2.dll

Declaration

public event EventHandler<SaveComponentsEventArgs> SaveComponents
Public Event SaveComponents As EventHandler(Of SaveComponentsEventArgs)

Event Data

The SaveComponents event's data class is SaveComponentsEventArgs. The following properties provide information specific to this event:

Property Description
Components Provides access to the list of components that will be saved along with a report's layout into a REPX file.

Remarks

Handle the SaveComponents event to customize the list of components to be saved along with a report to an REPX report definition file. To do this, use the SaveComponentsEventArgs.Components property. Adding a particular component to this list will force its serialization to an REPX file, while to prevent a particular component from being saved, you simply need to remove it from the Components list.

The SaveComponents event fires only when a report is saved to a report definition file (REPX) using the CodeDOM serialization (e.g., on calling the XtraReport.SaveLayout method). This is why, this event is not raised on saving a report in the End-User Report Designer where XML serialization is used by default.

For more information on handling events, see Events and Delegates in MSDN.

Examples

This example demonstrates how to exclude a DataSet, along with its TableAdapter, when saving a report definition to an REPX file. To do this, it is necessary to handle the XtraReport.SaveComponents event, and customize its SaveComponentsEventArgs.Components collection.

using System;
using System.ComponentModel;
using System.Data;
using System.Windows.Forms;
using System.Collections;
using DevExpress.XtraReports.UI;
// ...

private void Form1_Load(object sender, EventArgs e) {
    XtraReport1 report = new XtraReport1();
    report.SaveComponents += new 
        EventHandler<SaveComponentsEventArgs>(report_SaveComponents);
    report.ShowDesignerDialog();
}

void report_SaveComponents(object sender, SaveComponentsEventArgs e) {
    int tableAdapterIdx = GetItemIndex(e.Components, typeof(Component));
    if (tableAdapterIdx >= 0)
        e.Components.RemoveAt(tableAdapterIdx);
    int dsIdx = GetItemIndex(e.Components, typeof(DataSet));
    if (dsIdx >= 0)
        e.Components.RemoveAt(dsIdx);
}

private static int GetItemIndex(IList components, Type targetType) {
    int idx = -1;
    for (int i = 0; i < components.Count; i++) {
        if (components[i].GetType().BaseType == targetType) {
            idx = i;
            break;
        } 
    }

    return idx;
}
See Also