ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MappingExtensions Class / SelectElements Method / SelectElements(MapView,Geometry,SelectionCombinationMethod,Boolean) Method
The mapView that contains the graphics layer..
The selection geometry
Combination method used in selection operation
This parameter only applies to 2D. Indicates whether only features that are completely within the geometry should be selected.
Example

In This Topic
    SelectElements(MapView,Geometry,SelectionCombinationMethod,Boolean) Method
    In This Topic
    Select elements on all visible graphics layers that visually intersect a geometry. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overloads Shared Function SelectElements( _
       ByVal mapView As MapView, _
       ByVal geometry As Geometry, _
       Optional ByVal method As SelectionCombinationMethod, _
       Optional ByVal isWhollyWithin As Boolean _
    ) As IReadOnlyList(Of Element)

    Parameters

    mapView
    The mapView that contains the graphics layer..
    geometry
    The selection geometry
    method
    Combination method used in selection operation
    isWhollyWithin
    This parameter only applies to 2D. Indicates whether only features that are completely within the geometry should be selected.

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    geometry cannot be null or empty
    graphics layer is not associated with this view
    Remarks
    Currently, graphics layers are only supported for 2D.
    . Selection against elements always uses visual intersection as opposed to geometric intersection (of the search geometry with the element geometry). The graphics layers must be visible and selectable.
    Use SelectElements(MapView,GraphicsLayer,Geometry,SelectionCombinationMethod,Boolean) to select against just one individual graphics layer.
    Example
    Spatial selection of elements in all Graphics Layers
    //Map Tool is used to perform Spatial selection.
    //Graphic selection uses the selection geometry 
    //to intersect the geometries of those elements (graphic or group) 
    //that will be selected and then highlights them. 
    protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
    {
      var selPoly = geometry as Polygon;
      return await QueuedTask.Run(() =>
      {     
        //note: the selected elements may belong to more than one layer...
        var elems = MapView.Active.SelectElements(selPoly, SelectionCombinationMethod.New);
        return true;
      });
    }
    Spatial selection of elements in one graphics layer
    //on the QueuedTask
    //Create an extent to use for the spatial selection
    var extent = MapView.Active.Extent;
    var selectionExtent = extent.Expand(0.5, 0.5, true);
    //Select elements in specified graphics layer using the selection extent.
    var selectedElements = MapView.Active.SelectElements(graphicsLayer, selectionExtent, SelectionCombinationMethod.Add);
    Spatial selection of elements in one graphics layer
    //on the QueuedTask
    //Create an extent to use for the spatial selection
    var extent = MapView.Active.Extent;
    var selectionExtent = extent.Expand(0.5, 0.5, true);
    //Select elements in specified graphics layer using the selection extent.
    var selectedElements = MapView.Active.SelectElements(graphicsLayer, selectionExtent, SelectionCombinationMethod.Add);
    Select Text Graphic Elements
    var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList()
                        .OfType<ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault();
    if (graphicsLayer == null)
      return;
    var all_text = graphicsLayer.GetElementsAsFlattenedList()
                  .Where(e => e.GetGraphic() is CIMTextGraphic);
    Select Text Graphic Elements
    var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList()
                        .OfType<ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault();
    if (graphicsLayer == null)
      return;
    var all_text = graphicsLayer.GetElementsAsFlattenedList()
                  .Where(e => e.GetGraphic() is CIMTextGraphic);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also