ArcObjects Library Reference

Clear Selected Map Features Snippet

Clear the selected features in the IActiveView for a specified IFeatureLayer.

[C#]

///<summary>Clear the selected features in the IActiveView for a specified IFeatureLayer.</summary>
/// 
///<param name="activeView">An IActiveView interface</param>
///<param name="featureLayer">An IFeatureLayer</param>
/// 
///<remarks></remarks>
public void ClearSelectedMapFeatures(ESRI.ArcGIS.Carto.IActiveView activeView, ESRI.ArcGIS.Carto.IFeatureLayer featureLayer)
{
  if(activeView == null || featureLayer == null)
  {
    return;
  }
  ESRI.ArcGIS.Carto.IFeatureSelection featureSelection = featureLayer as ESRI.ArcGIS.Carto.IFeatureSelection; // Dynamic Cast

  // Invalidate only the selection cache. Flag the original selection
  activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);

  // Clear the selection
  featureSelection.Clear();

  // Flag the new selection
  activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, null, null);
}
[Visual Basic .NET]

'''<summary>Clear the selected features in the IActiveView for a specified IFeatureLayer.</summary>
''' 
'''<param name="activeView">An IActiveView interface</param>
'''<param name="featureLayer">An IFeatureLayer</param>
''' 
'''<remarks></remarks>
Public Sub ClearSelectedMapFeatures(ByVal activeView As ESRI.ArcGIS.Carto.IActiveView, ByVal featureLayer As ESRI.ArcGIS.Carto.IFeatureLayer)

  If activeView Is Nothing OrElse featureLayer Is Nothing Then

    Return

  End If

  Dim featureSelection As ESRI.ArcGIS.Carto.IFeatureSelection = TryCast(featureLayer, ESRI.ArcGIS.Carto.IFeatureSelection) ' Dynamic Cast

  ' Invalidate only the selection cache. Flag the original selection
  activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

  ' Clear the selection
  featureSelection.Clear()

  ' Flag the new selection
  activeView.PartialRefresh(ESRI.ArcGIS.Carto.esriViewDrawPhase.esriViewGeoSelection, Nothing, Nothing)

End Sub


Additional Requirements
  • The code in this document requires the following References added to the Visual Studio project:
  • ESRI.ArcGIS.Carto
  • ESRI.ArcGIS.Geometry