DataSourceInfoCollection.DataSourceRemoved Event
Occurs when removing the data source from the collection.
Namespace: DevExpress.Snap.Core.API
Assembly: DevExpress.Snap.v21.2.Core.dll
NuGet Package: DevExpress.Snap.Core
Declaration
Event Data
The DataSourceRemoved event's data class is DataSourceRemovedEventArgs. The following properties provide information specific to this event:
Property | Description |
---|---|
DataSourceInfo | Provides access to information about the target data source. |
IsDataSourceInternal | Gets whether the data source is internal (loaded with the document template or added in the UI using the Data Source Wizard) or external (added manually or used in other parts of the application). |
Remarks
Handle this event to safely dispose of the data source for further modification.
Before disposing of any data source related to the SnapDocument, check the DataSourceRemovedEventArgs.IsDataSourceInternal property. If true, the retrieved data source was loaded with the report template or added using the Data Source Wizard. This kind of data source can be safely disposed of. Otherwise, the selected data source is external or used in another parts of the application, thus the additional information is required for further operations.
If the data source is removed manually using the DataSourceInfoCollection.Remove method, the event is raised as well.
The code snippet below demonstrates how to safely discard of the data source.
Example
public Form1()
{
InitializeComponent();
this.snapControl1.Document.DataSources.DataSourceRemoved += OnDataSourceRemoved;
}
void OnDataSourceRemoved(object sender, DevExpress.Snap.DataSourceRemovedEventArgs e)
{
if (e.IsDataSourceInternal)
{
IDisposable disposable = e.DataSourceInfo.DataSource as IDisposable;
if (disposable != null) { disposable.Dispose(); }
}
}