"Are you sure you want to delete this feature" - Undo, Rollback, or Abort Feature Delete

694
2
Jump to solution
06-01-2017 06:10 AM
MKa
by
Occasional Contributor II

I am using IEditEvents_OnDeleteFeatureEventHandler to handle the processing of some things when the delete happens.  However, sometimes I would like to rollback this delete if for instance the "Area is Locked" in another system that doesn't want this area or polygon changed.  So I check another system on Delete, and if that system doesn't want the polygon deleted I want to roll back.  I have tried AbortOperation, Undo(), UndoOperation(), throw new COMException, and using OriginalShape().

This is the only way I could get the feature to rollback, and it isn't clean.  This solution displays my messagebox and then the abortoperation triggers an ArcMap message box that says "The features could not be deleted. OnDelete message to object returned failure [Ag_Field]".  

if (IsAreaVerified == "Yes")
{
    string warningMessage = "Current field Area Locked, Cannot Delete";
    DialogResult dialogResult = MessageBox.Show(warningMessage, "Area Verified", MessageBoxButtons.OK,    MessageBoxIcon.Error);
    pEditor.AbortOperation();
    return;
}

I have tried to get the THROW to work as some documentation says, but to no avail.  It is almost like i need a BeforeDelete Handler.

There has to be an easier way to simply ask a user "Are you sure you want to delete this feature"

Matt

Reply
0 Kudos
1 Solution

Accepted Solutions
JeffMatson
Occasional Contributor III

Have you looked at IEditEvents2_BeforeStopOperationEventHandler?

View solution in original post

2 Replies
JeffMatson
Occasional Contributor III

Have you looked at IEditEvents2_BeforeStopOperationEventHandler?

View solution in original post

MKa
by
Occasional Contributor II

This does the trick.  Thank You.

private IEditEvents2_Event Events2
{
   get { return ArcMap.Editor as IEditEvents2_Event; }
}

Events2.OnStopOperation += new IEditEvents2_OnStopOperationEventHandler(Events2_OnStopOperation);

void Events2_OnStopOperation()
{
     if (!CanDeleteReshape)
   {
       string warningMessage = "Current field Area Locked, Cannot Delete";
      DialogResult dialogResult = MessageBox.Show(warningMessage, "Area Verified", MessageBoxButtons.OK,        MessageBoxIcon.Error);
       ArcMap.Editor.UndoOperation();
   }
}