This document is archived and information here might be outdated.  Recommended version.


How to listen to workspace edit events (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > Developing with ArcGIS > Learning ArcObjects > Editing data > Editing with the geodatabase API > How to listen to workspace edit events

How to listen to workspace edit events


Summary
The IWorkspaceEditEvents and IWorkspaceEditEvents2 interfaces allow developers to listen to events triggered by the beginning and end of edit sessions and edit operations. This topic describes how to use these interfaces and provides examples of scenarios where they should be used.

In this topic


Listening to workspace edit events

Workspace edit events allow applications to respond to methods called on the IWorkspaceEdit interface. The IWorkspaceEditEvents interface exposes the following seven events:
  • OnStartEditing
  • OnStopEditing
  • OnStartEditOperation
  • OnStopEditOperation
  • OnAbortEditOperation
  • OnUndoEditOperation
  • OnRedoEditOperation
The IWorkspaceEditEvents2 interface (new at ArcGIS 10) exposes the following additional event:
  • OnBeginStopEditing
With the exception of OnBeginStopEditing, all of the events are invoked when the IWorkspaceEdit method of the same name (minus "On") is called, for example, IWorkspaceEditEvents.OnStartEditing is invoked when IWorkspaceEdit.StartEditing is called.
OnStopEditing and OnBeginStopEditing are invoked when IWorkspaceEdit.StopEditing is called. The following is the difference between the two:
  • OnStopEditing is invoked after the edit session has been stopped, whereas OnBeginStopEditing is invoked immediately after the call to StopEditing has been made but before the edit session has been stopped.
The delegates for these events have the same parameters as their corresponding IWorkspaceEdit events. For example, StartEditing has a single Boolean parameter; therefore, the delegate for OnStartEditing also has a single Boolean parameter.

Subscribing to workspace edit events

Do the following to subscribe to workspace edit events:
  1. Create an event handler with the appropriate signature.
  2. Use the += operator (in C#) or the AddHandler function (in VB .NET).

    See the following code example:
Due to the default naming conventions for outbound Component Object Model (COM) interfaces in Interop assemblies, use IWorkspaceEditEvents_Event in .NET instead of IWorkspaceEditEvents.
[C#]
public void Subscribe(IWorkspace workspace)
{
    IWorkspaceEditEvents_Event workspaceEditEvents=(IWorkspaceEditEvents_Event)
        workspace;
    workspaceEditEvents.OnStartEditing += new
        IWorkspaceEditEvents_OnStartEditingEventHandler(OnStartEditingHandler);
}

private void OnStartEditingHandler(Boolean withUndoRedo)
{
    // Implement the behavior here...
}
[VB.NET]
Public Sub Subscribe(ByVal workspace As IWorkspace)
    Dim workspaceEditEvents As IWorkspaceEditEvents_Event=CType(workspace, IWorkspaceEditEvents_Event)
    AddHandler workspaceEditEvents.OnStartEditing, AddressOf OnStartEditingHandler
End Sub

Private Sub OnStartEditingHandler(ByVal withUndoRedo As Boolean)
    ' Implement the behavior here...
End Sub

Using workspace edit event scenarios

The following are the two main scenarios where workspace edit events are used:
  • In editing applications that cache rows across edit operations. If a user edits a row within an edit operation, that edit operation is aborted and the row should be re-fetched from the geodatabase.
  • In applications or custom components that need to internally track the state of edits or the features that have been edited.
IWorkspaceEditEvents2.OnBeginStopEditing was introduced to support a specific use case - determining the changes that have been made over the course of an edit session as it is completed using the IWorkspaceEdit2.EditDataChanges property.


See Also:

How to wire ArcObjects .NET events




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
ArcGIS Desktop Standard ArcGIS Desktop Standard
ArcGIS Desktop Advanced ArcGIS Desktop Advanced
Engine Developer Kit Engine: Geodatabase Update