ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / GraphicsLayerExtensions Class / ClearSelection Method
Example

In This Topic
    ClearSelection Method (GraphicsLayerExtensions)
    In This Topic
    Clears the current element selection within the GraphicsLayer collection. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public static void ClearSelection( 
       GraphicsLayer graphicsLayer
    )
    Public Shared Sub ClearSelection( _
       ByVal graphicsLayer As GraphicsLayer _
    ) 

    Parameters

    graphicsLayer
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    The map view displaying the graphics layer should be initialized.
    Example
    Add the Most Recent Location To A Graphics Layer
    {
      await QueuedTask.Run(() =>
      {
        // get the last location
        var pt = DeviceLocationService.Instance.GetCurrentSnapshot()?.GetPositionAsMapPoint();
        if (pt != null)
        {
          //Create a point symbol
          var ptSymbol = SymbolFactory.Instance.ConstructPointSymbol(
                            CIMColor.CreateRGBColor(125, 125, 0), 10, SimpleMarkerStyle.Triangle);
          //Add a graphic to the graphics layer
          graphicsLayer.AddElement(pt, ptSymbol);
          //unselect it
          graphicsLayer.ClearSelection();
        }
      });
    }
    Un-Select Graphic elements
    {
      await QueuedTask.Run(() =>
      {
        //unselect the first element in the currently selected elements
        var elem = graphicsLayer.GetSelectedElements().FirstOrDefault();
        if (elem != null)
        {
          //Unselect one element
          graphicsLayer.UnSelectElement(elem);
        }
    
        //unselect all elements
        graphicsLayer.UnSelectElements();
        //equivalent to
        graphicsLayer.ClearSelection();
      });
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also