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


IMap.FeatureSelection Property (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Carto > ESRI.ArcGIS.Carto > Interfaces > IM > IMap Interface > IMap.FeatureSelection Property
ArcGIS Developer Help

IMap.FeatureSelection Property

The feature selection for the map.

[Visual Basic .NET]
Public Property FeatureSelection As ISelection
[C#]
public ISelection FeatureSelection {get; set;}
[C++]
HRESULT get_FeatureSelection(
  ISelection** Selection
);
[C++]
HRESULT putref_FeatureSelection(
  ISelection* Selection
);
[C++]
Parameters
Selection [out, retval]

Selection is a parameter of type ISelection** Selection [in]
Selection is a parameter of type ISelection*

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Remarks

ArcMap has two different selections, a feature selection and an element selection. Two different objects represent these selections and both implement the ISelection interface.  The feature selection object additionally implements IEnumFeature and the element selection object IEnumElement. The ISelection interface is used for clipboard type operations and the IEnum interfaces are used to loop through the items in the collection. 

When you ask for the FeatureSelection from IMap you are returned an ISelection but you can perform a query interface for IEnumFeature and usually do so. However, if you get the selection via IActiveView::Selection, the selection can either be an element selection or a feature selection depending on which one is currently active - only one of the selections can be active at a time.  Use FeatureSelection to ensure a reference to the correct selection.

IEnumFeature works on all of the FeatureLayers as a whole. Each FeatureLayer has a ISelectionSet and IEnumFeature steps through all of these as though there was only one. Because IEnumFeature works with all the FeatureLayers, you cannot use it to loop through the features belonging to just one FeatureLayer.

Note, only the shape field is guaranteed with the selection. This is the default and exists for performance reasons. The IMap::FeatureSelection property is typically used to draw the map selection, not access feature attributes. This is particularly noticeable with shapefiles and coverage but also in geodatabases if the selection is large enough. Use IEnumFeatureSetup::AllFields to set a flag indicating all fields be returned with the selection. If you want to loop through the map selection to perform an operation, it is typically best to access each layer's selection rather than the entire map's selection. See the example for a sample of each.

See Also

IMap Interface | IActiveView.Selection Property | ElementSelection Class

.NET Samples

Move a graphic along a path in ArcMap Implementing an XML builder external component