ArcGIS Pro 3.3 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
    Load map selection into Inspector
    // get the currently selected features in the map
    var selectedFeatures = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection();
    // get the first layer and its corresponding selected feature OIDs
    var firstSelectionSet = selectedFeatures.ToDictionary().First();
    
    // create an instance of the inspector class
    var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();
    // load the selected features into the inspector using a list of object IDs
    await inspector.LoadAsync(firstSelectionSet.Key, firstSelectionSet.Value);
    Get selected feature's attribute value
    QueuedTask.Run(() =>
    {
    
      // get the currently selected features in the map
      var selectedFeatures = ArcGIS.Desktop.Mapping.MapView.Active.Map.GetSelection();
    
      // get the first layer and its corresponding selected feature OIDs
      var firstSelectionSet = selectedFeatures.ToDictionary().First();
    
      // create an instance of the inspector class
      var inspector = new ArcGIS.Desktop.Editing.Attributes.Inspector();
    
      // load the selected features into the inspector using a list of object IDs
      inspector.Load(firstSelectionSet.Key, firstSelectionSet.Value);
    
      //get the value of
      var pscode = inspector["STATE_NAME"];
      var myGeometry = inspector.Shape;
    });
    Flash selected features
    public Task FlashSelectedFeaturesAsync()
    {
      return QueuedTask.Run(() =>
      {
        //Get the active map view.
        var mapView = MapView.Active;
        if (mapView == null)
          return;
    
        //Get the selected features from the map and filter out the standalone table selection.
    
        //At 2.x
        //var selectedFeatures = mapView.Map.GetSelection()
        //    .Where(kvp => kvp.Key is BasicFeatureLayer)
        //    .ToDictionary(kvp => (BasicFeatureLayer)kvp.Key, kvp => kvp.Value);
    
        ////Flash the collection of features.
        //mapView.FlashFeature(selectedFeatures);
    
        var selectedFeatures = mapView.Map.GetSelection();
    
        //Flash the collection of features.
        mapView.FlashFeature(selectedFeatures);
      });
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also