ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Map Class / GetSelection Method
Example

In This Topic
    GetSelection Method (Map)
    In This Topic
    Get the selection for the map. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public SelectionSet GetSelection()
    Public Function GetSelection() As SelectionSet

    Return Value

    The selection in the map represented by the collection of layers and tables and their corresponding object ids.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Check SelectionSet Equality
    {
      // get map selection
      var mapSelSet = MapView.Active.Map.GetSelection();
    
      // create a selectionSet
      var selDict = new Dictionary<MapMember, List<long>>();
      selDict.Add(featureLayer, new List<long> { 1506, 2696, 2246, 1647, 948 });
      var layerSelSet = ArcGIS.Desktop.Mapping.SelectionSet.FromDictionary(selDict);
    
      // test for equality - use Equals method
      var isEquals = mapSelSet.Equals(layerSelSet);
    
      // test for equality - use operators
      var equals = mapSelSet == layerSelSet;
      var notEquals = mapSelSet != layerSelSet;
    }
    Flash selected features
    {
      await QueuedTask.Run(() =>
      {
        //Get the selected features from the map and filter out the standalone table selection.
        var selectedFeatures = mapView.Map.GetSelection();
    
        //Flash the collection of features.
        mapView.FlashFeature(selectedFeatures);
      });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also