Skip to main content
.NET 6.0+

IObjectSpace.CustomDeleteObjects Event

The IObjectSpace.Delete method raises the CustomDeleteObjects event. Handle this event to replace the default persistent object deletion logic with custom logic.

Namespace: DevExpress.ExpressApp

Assembly: DevExpress.ExpressApp.v23.2.dll

NuGet Package: DevExpress.ExpressApp

Declaration

event EventHandler<CustomDeleteObjectsEventArgs> CustomDeleteObjects

Event Data

The CustomDeleteObjects event's data class is DevExpress.ExpressApp.CustomDeleteObjectsEventArgs.

Remarks

Use the handler’s CustomDeleteObjectsEventArgs.Objects parameter to get the objects to be deleted. Set the handler’s CompletedEventArgs.Handled parameter to true to indicate that the delete operation has already been performed.

The Controller below specifies the IsMarkedAsDeleted property of CustomDeleteObjectsEventArgs.Objects instead of removing them:

File: MySolution.Module\Controllers\CustomDeleteObjectController.cs(.vb).

using DevExpress.ExpressApp;
// ...
public class CustomDeleteObjectController : ObjectViewController<DetailView, Employee> {
    protected override void OnActivated() {
        base.OnActivated();
        ObjectSpace.CustomDeleteObjects += ObjectSpace_CustomDeleteObjects;
    }
    private void ObjectSpace_CustomDeleteObjects(object sender, CustomDeleteObjectsEventArgs e) {
        foreach (object deletingObject in e.Objects) {
            Employee employee = ObjectSpace.GetObject(deletingObject) as Employee;
            // IsMarkedAsDeleted is a custom Employee's property
            employee.IsMarkedAsDeleted = true;
        }
        e.Handled = true;
    }
    protected override void OnDeactivated() {
        ObjectSpace.CustomDeleteObjects -= ObjectSpace_CustomDeleteObjects;
        base.OnDeactivated();
    }
}

Note

If you implement the IObjectSpace interface in the BaseObjectSpace class descendant, you can override the BaseObjectSpace.DeleteCore method instead of handling the CustomDeleteObjects event. The BaseObjectSpace.Delete method calls the BaseObjectSpace.DeleteCore method and raises the CustomDeleteObjects event. This allows you to implement custom persistent object deletion logic in any of these places. For more information, refer to the IObjectSpace.Delete method description.

See Also