1

I want listen to Edit Session in ArcMap. But every time when i click on my button in ArcMap, Applicaation crash down. If i debug, it stopped at AddHandler Events.OnStartEditing, AddressOf Events_OnStartEditing under Sub Button1.

Error: Task In order to evaluate an indexed property, the property must be qualified and the arguments must be explicitly supplied by the user. ESRI.ArcGIS.Editor.IEditTask

Code:

Imports System.Runtime.InteropServices
Imports ESRI.ArcGIS.esriSystem
Imports ESRI.ArcGIS.Editor
Imports ESRI.ArcGIS.Desktop.AddIns
Imports ESRI.ArcGIS.Geodatabase
Imports ESRI.ArcGIS.Carto
Imports ESRI.ArcGIS.Framework
Imports ESRI.ArcGIS.ArcMap
Imports ESRI.ArcGIS.SystemUI

Public Class Button1
    Inherits ESRI.ArcGIS.Desktop.AddIns.Button

    Public Sub New()

    End Sub
    Protected Overrides Sub OnUpdate()
        Enabled = My.ArcMap.Application IsNot Nothing
    End Sub

    Protected Overrides Sub OnClick()
        AddHandler Events.OnStartEditing, AddressOf Events_OnStartEditing
        AddHandler Events.OnStopEditing, AddressOf Events_OnStopEditing
    End Sub

    Private ReadOnly Property MyEditor() As IEditor
        Get
            Dim m_editor As IEditor
            Dim editorUid As New UID()
            editorUid.Value = "esriEditor.Editor"
            m_editor = TryCast(My.ArcMap.Application.FindExtensionByCLSID(editorUid), IEditor)
            Return TryCast(m_editor, IEditor)
        End Get
    End Property

    Private ReadOnly Property Events() As IEditEvents_Event
        Get
            Dim m_editorEvents As IEditEvents_Event = TryCast(MyEditor, IEditEvents_Event)
            Return TryCast(m_editorEvents, IEditEvents_Event)
        End Get
    End Property

    Private Sub Events_OnStartEditing()
        MsgBox("you are now editing")
    End Sub

    Private Sub Events_OnStopEditing()
        MsgBox("You will stop editing")
    End Sub
End Class

1 Answer 1

1

It's been some time since I have had to create code that would listen out for editor events. I looked at my old code and the main difference is that I set up the edit events in an EXTENSION not within the code of button. This is probably where you are going wrong?

Below is the basic structure of my code:

Public Class MY_Extension
    Inherits ESRI.ArcGIS.Desktop.AddIns.Extension

    Private WithEvents m_EditEvents As Editor
    Private m_Editor As IEditor3

    Protected Overrides Sub OnStartup()
        ' Hook into editor
        Dim pUID As New UID
        pUID.Value = "esriEditor.Editor"
        m_Editor = My.ArcMap.Application.FindExtensionByCLSID(pUID)
        m_EditEvents = m_Editor
    End Sub

    Private Sub m_EditEvents_OnCreateFeature(obj As ESRI.ArcGIS.Geodatabase.IObject) Handles m_EditEvents.OnCreateFeature
        ' Do something
    End Sub

    Protected Overrides Sub OnShutdown()
        m_Editor = Nothing
        m_EditEvents = Nothing
    End Sub
End Class

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.