.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
.NET 5.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.v21.2.dll

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 following example illustrates how to execute the custom deletion logic instead of the default logic in the CustomDeleteObjects event handler. The Controller below specifies the IsMarkedAsDeleted property of CustomDeleteObjectsEventArgs.Objects instead of removing them.

using System;
using DevExpress.ExpressApp;
// ...
namespace MySolution.Module.Controllers {
    public class CustomDeleteObjectController : ObjectViewController<DetailView, Employee> {
        protected override void OnActivated() {
            base.OnActivated();
            ObjectSpace.CustomDeleteObjects += new EventHandler<CustomDeleteObjectsEventArgs>(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 -= new EventHandler<CustomDeleteObjectsEventArgs>(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