How to listen to edit events (ArcObjects .NET 10.6 SDK)
ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Editing data > ArcGIS Engine editing > How to listen to edit events (ArcObjects .NET 10.6 SDK)

How to listen to edit events


Summary
This topic describes how to listen to IEngineEditEvents using the OnStartEditing event as an example.

In this topic


About listening to IEngineEditEvents

The IEngineEditEvents interface is an outbound interface on the EngineEditor singleton object that notifies listeners of editing actions. Events can be fired in response to end user interaction or program logic. For example, the IEngineEditEvents.OnStartEditing event is raised by using the out-of-the-box ControlsEditingStartCommand or when IEngineEditor.StartEditing is called.
To listen for specific IEngineEditEvents, create an event handler that is linked with the event using a delegate. The delegate holds a reference to a method that executes if the event is fired. The event handler method must have the same signature as the delegate. This process is known as wiring. For more information, see How to wire ArcObjects .NET events.

Listening to IEngineEditEvents

To listen to IEngineEditEvents, perform the following steps. In the following code example, a listener is created to determine when an editing session has started.
  1. At the class level, declare the following two variables: 
    • Variable to the EngineEditor singleton object
    • Variable to the IEngineEditEvents interface
In .NET, event interfaces are automatically suffixed with _Event by the type library importer.
[C#]
private EngineEditor m_EngineEditor=new EngineEditorClass();
private IEngineEditEvents_Event m_EngineEditEvents;
[VB.NET]
Private m_EngineEditor As EngineEditor=New ESRI.ArcGIS.Controls.EngineEditorClass()
Private m_EngineEditEvents As IEngineEditEvents_Event
  1. In the Form_Load, cast the IEngineEditEvents interface to the EngineEditor singleton object. See the following code example:
[C#]
m_EngineEditEvents=(IEngineEditEvents_Event)m_EngineEditor;
[VB.NET]
m_EngineEditEvents=CType(m_EngineEditor, IEngineEditEvents_Event)
  1. In the Form_Load, register the event handler method that will be called when the event is fired. Use the AddHandler statement (VB .NET) or the += statement (C#) to register the event handler method. See the following code example:
[C#]
m_EngineEditEvents.OnStartEditing += new
    IEngineEditEvents_OnStartEditingEventHandler(OnStartEditingMethod);
[VB.NET]
AddHandler m_EngineEditEvents.OnStartEditing, AddressOf OnStartEditingMethod
  1. At the class level, define the method that is performed when the IEngineEditEvents.OnStartEditing event is fired. See the following code example:
[C#]
private void OnStartEditingMethod()
{
    System.Windows.Forms.MessageBox.Show("Editing Started");
}
[VB.NET]
Private Sub OnStartEditingMethod()
    System.Windows.Forms.MessageBox.Show("Editing Started")
End Sub

Event order

One editing command or method may fire a number of specific IEngineEditEvents. See the following:
It is important to understand the order in which events are fired so that customized code associated with the events executes in the correct order.


See Also:

How to wire ArcObjects .NET events
How to create an edit session
How to create a sketch operation
How to work with the operation stack




To use the code in this topic, reference the following assemblies in your Visual Studio project. In the code files, you will need using (C#) or Imports (VB .NET) directives for the corresponding namespaces (given in parenthesis below if different from the assembly name):
Development licensing Deployment licensing
Engine Developer Kit Engine
ArcGIS for Desktop Basic
ArcGIS for Desktop Standard
ArcGIS for Desktop Advanced