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

1575
5
Jump to solution
06-01-2017 06:10 AM
MKa
by
Occasional Contributor III

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

0 Kudos
1 Solution

Accepted Solutions
JeffMatson
Occasional Contributor III

Have you looked at IEditEvents2_BeforeStopOperationEventHandler?

View solution in original post

5 Replies
JeffMatson
Occasional Contributor III

Have you looked at IEditEvents2_BeforeStopOperationEventHandler?

MKa
by
Occasional Contributor III

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();
   }
}

BrianBulla
Occasional Contributor III

Hi,

In your code above what is !CanDeleteReshape??

I'm working on something similar, to stop a delete and update some attributes instead.

Thanks!

0 Kudos
WWalker
New Contributor III

Did you ever figure out a solution?  I've been looking for a solution for some time.  I've posted a similar question over on the stack exchange: https://gis.stackexchange.com/q/441626/18981

0 Kudos
BrianBulla
Occasional Contributor III

Hi.  No, I have not been able to get this to work.  I haven't looked at it in a while, but might re-visit this and see if having a second look at it might help.

0 Kudos