ArcGIS Pro 3.7 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 Function GetSelection() As SelectionSet
    public SelectionSet GetSelection()

    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
    {
      // Loads the selected features into an Inspector instance.
      // 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 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
    // Retrieves the value of a specific attribute and the geometry of the first selected feature from the provided selection set.
    await QueuedTask.Run(() =>
    {
      // 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 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
    {
      // Note: Needs QueuedTask to 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