ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / Layout Class / DeleteElements Method / DeleteElements(Func<Element,Boolean>) Method
Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.
Example

In This Topic
    DeleteElements(Func<Element,Boolean>) Method
    In This Topic
    Deletes an array of elements on a page layout. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void DeleteElements( 
       Func<Element,bool> predicate
    )
    Public Overloads Sub DeleteElements( _
       ByVal predicate As Func(Of Element,Boolean) _
    ) 

    Parameters

    predicate
    Represents the method that defines a set of criteria and determines whether the specified object meets those criteria.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Example
    Layout_DeleteElements
    //Delete multiple layout elements.
    
    //Perform on the worker thread
    await QueuedTask.Run(() =>
    {
      layout.DeleteElements(item => item.Name.Contains("Clone"));
    });
    Delete Layout Elements
    //on the QueuedTask  
    var elementsToRemove = layout.GetSelectedElements();
    layout.DeleteElements(elementsToRemove);
    Delete an element or elements on a layout
    //Delete an element or elements on a layout.
    
    //Perform on the worker thread
    QueuedTask.Run(() =>
    {
      //Delete a specific element on a layout
      aLayout.DeleteElement(elm);
     
      //Or delete a group of elements using a filter
      aLayout.DeleteElements(item => item.Name.Contains("Clone"));
    
      //Or delete all elements on a layout
      aLayout.DeleteElements(item => true);
    });
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also