HierarchyInfo.OnDeleting(CancelEventArgs) Method

Definition

Occurs when the Delete() method is called from the user interface (UI) or programmatically.

protected:
 virtual void OnDeleting(System::ComponentModel::CancelEventArgs ^ e);
protected virtual void OnDeleting (System.ComponentModel.CancelEventArgs e);
abstract member OnDeleting : System.ComponentModel.CancelEventArgs -> unit
override this.OnDeleting : System.ComponentModel.CancelEventArgs -> unit
Protected Overridable Sub OnDeleting (e As CancelEventArgs)

Parameters

e
CancelEventArgs

A CancelEventArgs that contains the event data.

Examples

The following example will cancel the Delete method based on a random Boolean value.

public bool DemoDelete()
{
    bool bCancel = SH.nextRandBool();
    Trace.WriteLine("OnDeleting called on " + Text +
     " at " + System.DateTime.Now.ToString()
     + " Cancel Delete = " + bCancel.ToString());
    return bCancel;     // return cancel choice
}

protected override void OnDeleting(System.ComponentModel.CancelEventArgs e)
{
    e.Cancel = !DemoDelete();
}

Remarks

If the application supports deleting, call your application-specific Delete method here. Setting the <xref:System.ComponentModel.CancelEventArgsCancel?displayProperty=fullName> property to false will prevent the Delete method from being called and the node will not be removed from the UI tree.

Applies to