An ISelectionSet may not initially be assigned a value after the ISelectionEvents::SelectionChanged event is fired


Starting in ArcGIS 9.2, when a given selection is changed, multiple events are raised: two when clearing the current selection, and one more when the new selection is made.

Because of this, any functions written by a developer for handling the change in selection may try to access the selection set before it is assigned the value of the new selection. If this occurs, an error results.


This behavior is by design.

Solution or Workaround

To prevent the error, check to be sure the selection set is not null before accessing it in an event handler. ArcObjects developers should always check to be sure that a variable is initialized before reading or writing to it. An example from the VB6 SDK help for ISelectionEvents is shown below:
[Visual Basic 6.0]
' Respond to selection events
Private Sub m_pSelectionEvents_SelectionChanged()
If m_pMap Is Nothing Then Exit Sub ' no map exit...
If m_pMap.SelectionCount = 0 Then Exit Sub ' no selection nothing to do...
MsgBox m_pMap.SelectionCount & " feature(s) are selected."
End Sub

The two events prior to the final selection must be handled and the selection set can be accessed only after it is assigned the new value.

Because this behavior is different from ArcGIS 9.1, developers may need to revise and/or recompile older customizations to reflect this change.

    Article ID:000009803

    • ArcGIS Engine
    • ArcMap

    Get help from ArcGIS experts

    Contact technical support

    Download the Esri Support App

    Go to download options

    Related Information

    Discover more on this topic