XtraReport.SaveComponents Event
Occurs when a report is saved to a REPX file using CodeDOM serialization. Allows you to define which components should be saved in the report definition file.
Namespace: DevExpress.XtraReports.UI
Assembly: DevExpress.XtraReports.v23.1.dll
NuGet Package: DevExpress.Reporting.Core
Declaration
Event Data
The SaveComponents event's data class is SaveComponentsEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
Components | Gets the list of components that are saved with the report layout to a REPX file. |
Remarks
You can handle the SaveComponents event to customize the list of components that are saved with the report to the REPX report definition file. The SaveComponentsEventArgs.Components property is used for this purpose. If you add a component to this list, it is serialized and saved to a REPX file. To exclude a particular component, remove it from the Components list.
Note
The SaveComponents event occurs only when a report is saved to a report definition file (REPX) using CodeDOM serialization. This event does not occur in End-User Report Designer, where XML serialization is used by default.
Example
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;
}