EditOperation Automaticly started with Event "OnDeleteFeature"?

770
6
03-24-2011 06:13 AM
LionelMartz
New Contributor II
Hello everyone again,

I've just a little question to make sure, that everything doesn't work just by a fluke.
I'm handling the Events "OnVertexAdded" and "OnDeleteFeature".

In my OnDeleteFeature-handling it can be, that the delete-Operation is invalid. In this case, I call the editor.AbortOperation-method. That works fine. Does that mean, the ArcGIS is starting itself an edit operation? I Think this, because I also can't start an edit Operation in this event-handling without getting an Error. In contrast to the OnVertexAdded-event, where it is possible to start an Edit Operation.

In the API there is written, that the user must start an stop Operations while he's editing within an editor editing session.

So, it's a bit confusing for me..


Thanks for the answers!

Lionel
0 Kudos
6 Replies
AlexanderGray
Occasional Contributor III
If you are listening to OnDeleteFeature from the ArcMap editor extension, you should not abort the operation.  OnCreate, OnChange, OnDelete all happen inside an edit operation.  You should never try to stop or abort an operation from inside the listener.  If you need to void the operation, throw an exception with a message you want the user the see.  The exception will be caught in esri code and the esri code will abort the operation and show the user the message.
http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/d/000100000340000000.ht...
"Do not call AbortOperation inside any editor event, including BeforeStopOperation."
0 Kudos
LionelMartz
New Contributor II
Hello agray

thanks for your quick answer. I made everything you said. I handled the event and throwed an exception.
Unfortunately nothing happend.. but my feature was deleted anyway.

This is my code:
Private Sub EsriEditor_OnDeleteFeature(ByVal obj As ESRI.ArcGIS.Geodatabase.IObject) Handles EsriEditorEvents.OnDeleteFeature

        If CType(obj, IFeature).Class.AliasName = "Protected" Then
            Throw New Exception("This feature mustn't be deleted!")
        End If

    End Sub
0 Kudos
HXiao
by
New Contributor III
Hello, Lionel,
I got the same thing as you. Throwed an exception, but my feature was deleted without any message. Did you find a solution? Thanks.
0 Kudos
AlexanderGray
Occasional Contributor III
the event listener needs to be on the class extension event for the feature class you are editing not the editor events.
0 Kudos
HXiao
by
New Contributor III
Hello agray,

Thanks for your reply. I could not follow you yet. Do you mind giving a piece of code to help understand the difference?
0 Kudos
AlexanderGray
Occasional Contributor III
the code is a little scattered but I do this in an extension in vb.net, principle is the same for c#

class level member variable:
  Private m_PointObjectClassEvents As IObjectClassEvents_Event

In a method called on start editing, if the featureclass is found
'LayerPoint previousle obtained
m_PointObjectClassEvents = DirectCast(m_LayerPoint.FeatureClass, IObjectClassEvents_Event)
AddHandler m_PointObjectClassEvents.OnChange, AddressOf PointChange

Private Sub PointChange(ByVal obj As IObject)
     'Maybe check some conditions
     Throw New ApplicationException("Message to the user")  'this abort the edit and the exception
      'message is shown to the user
  End Sub

In a stop editing event or other appropriate event
RemoveHandler m_PointObjectClassEvents.OnDelete, AddressOf PointChange
0 Kudos