Select to view content in your preferred language

Events are buggy

512
3
02-18-2010 11:52 PM
RobertClark
Occasional Contributor
I have found the following bugs in the events classes (all still present from earlier versions of ArcMap)

ESRI.ArcGIS.Carto.IFeatureLayerSelectionEvents_Event.FeatureLayerSelectionChanged
If the selection rectangle drawn by the user did not select any records then this event is raised 3 times.
The event is raised when the layer is not visible, and it's raised 3 times too.
The event is raised when the layer is toggled as "not selectable".


ESRI.ArcGIS.Carto.IActiveViewEvents_Event.SelectionChanged
When clearing selection the event is raised twice.
Adding a new data frame raises this event, which it shouldn't.
When deleting a graphic and this event is being caught then the map does not refresh.  The event is also raised twice again.
The event is raised when a feature layer is removed from the map (the layer did not have a selection either).


ESRI.ArcGIS.Carto.IActiveViewEvents_Event.ItemReordered
The toIndex arguments always returns -2147483648.
A layer being added to or removed from the map that would alter the index of the layer thus 'reorder' does not raise this event.


ESRI.ArcGIS.Carto.IActiveViewEvents_Event.ContentsCleared
Could not get this event to be raised.  Not sure what it's mean't to do either as the documentation is not that specific.

ESRI.ArcGIS.Carto.IActiveViewEvents_Event.FocusMapChanged
The event does not get raised when the map focus changes.  Though IDocumentEvents_Event.ActiveViewChanged seems to work ok.

Some events seem to be missing from ArcObjects too to cover over changes in layer properties for example:

  • Field Visibility Changes

  • Field Aliases change

  • Data source changes in ILayer_Events

  • Primary display field is changed

  • Join/ relate added/changed/removed in ILayer_Events

0 Kudos
3 Replies
DavidPlume1
Occasional Contributor
Hi Rob

Yes, I found all that behavior a bit challenging too.

I set up document and ActiveView Events in an extension.  I found that I had to setup the document events only once.  I removed the events on extension shut down.

On the other hand, each time the document.ActiveViewChanged event is fired I remove my old events then add the new ones, see below.

Hope this helps.


Private Sub OnActiveViewChanged()

        Try

            Dim pActiveView As IActiveView = m_pMxDocument.ActiveView
            Dim pMap As IMap
            Dim pPageLayout As IPageLayout

            If TypeOf pActiveView Is IMap Then

                pMap = pActiveView.FocusMap
                m_pActiveViewEvents = CType(pMap, IActiveViewEvents_Event)
                Debug.Print("Active View is IMAP, FocusMap is:  " & pActiveView.FocusMap.Name)

            ElseIf TypeOf pActiveView Is IPageLayout Then

                pPageLayout = m_pMxDocument.PageLayout
                m_pActiveViewEvents = CType(pPageLayout, IActiveViewEvents_Event)
                Debug.Print("Active View is IPageLayout, FocusMap is:  " & pActiveView.FocusMap.Name)

            Else
                Return
            End If


            Me.RemoveActiveViewEvents()


            Me.AddActiveViewEvents()

        Catch ex As Exception
            DebugMsgBox("OnActiveviewChanged() Error: " & ex.ToString)
        End Try

    End Sub

   Public Sub AddActiveViewEvents()

        Try

            If m_pActiveViewEvents IsNot Nothing Then

                AddHandler m_pActiveViewEvents.FocusMapChanged, AddressOf OnActiveViewEventsFocusMapChanged
                AddHandler m_pActiveViewEvents.ItemAdded, AddressOf OnActiveViewEventsItemAdded
                AddHandler m_pActiveViewEvents.ItemDeleted, AddressOf OnActiveViewEventsItemDeleted
                DebugMsgBox("AddActiveViewEvents")
            Else
                DebugMsgBox("AddActiveViewEvents m_pActiveViewEvents = NOTHING")
            End If

        Catch ex As Exception

        End Try


    End Sub

    Public Sub RemoveActiveViewEvents()

        Try

            If m_pActiveViewEvents IsNot Nothing Then

                RemoveHandler m_pActiveViewEvents.FocusMapChanged, AddressOf OnActiveViewEventsFocusMapChanged
                RemoveHandler m_pActiveViewEvents.ItemAdded, AddressOf OnActiveViewEventsItemAdded
                RemoveHandler m_pActiveViewEvents.ItemDeleted, AddressOf OnActiveViewEventsItemDeleted

                DebugMsgBox("RemoveActiveViewEvents")
            Else
                DebugMsgBox("RemoveActiveViewEvents - m_pActiveViewEvents = NOTHING")
            End If

        Catch ex As Exception

        End Try


    End Sub
0 Kudos
LorenzMeyer
Emerging Contributor
I wrote my own Extension to catch the Documentevents. In the Startup of the extension i connect the Events as follows:
((IDocumentEvents_Event)_applicationReference.Document).NewDocument += new IDocumentEvents_NewDocumentEventHandler(NewDocumentEventHandler);
((IDocumentEvents_Event)_applicationReference.Document).OpenDocument += new IDocumentEvents_OpenDocumentEventHandler(OpenDocumentEventHandler);

If ArcMap gets started and my extension starts up, the events are not raised from ArcMap. If i set a breakpoint after the lines where I connect the events and inspect the "_applicationReference" and the "_applicationReference.Document" in Visual Studio, the events are raised. It's not a timing problem. Waiting on the breakpoint without inspecting the objects does not raise the events.

I think it's a bug, but I'm not shure...Any hints or ideas?
0 Kudos
TomCohen
Regular Contributor
On the other hand, each time the document.ActiveViewChanged event is fired I remove my old events then add the new ones, see below.

Hope this helps.
   


Thanks very much for posting this David, this helped me get around a major blocking bug on an ArcMap add-in. My ActiveView events were being persisted in 9.3, but not in 10. I really wish changes like this were documented.
0 Kudos