ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / LayoutView Class / SelectElements Method / SelectElements(IReadOnlyList<Element>) Method
A list of existing layout elements.
Example

In This Topic
    SelectElements(IReadOnlyList<Element>) Method
    In This Topic
    Set the selected layout elements for the layout view. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public void SelectElements( 
       IReadOnlyList<Element> elements
    )
    Public Overloads Sub SelectElements( _
       ByVal elements As IReadOnlyList(Of Element) _
    ) 

    Parameters

    elements
    A list of existing layout elements.
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    elements must belong to layout 'URI'
    Example
    LayoutView_SetSelection
    //Set the layout's element selection.
    
    await QueuedTask.Run(() =>
    {
      Element rec = layoutView.Layout.FindElement("Rectangle");
      Element rec2 = layoutView.Layout.FindElement("Rectangle 2");
    
      List<Element> elmList = new List<Element>();
      elmList.Add(rec);
      elmList.Add(rec2);
    
      layoutView.SelectElements(elmList);
    });
    LayoutViewClassExample1
    //This example references the active layout view.  Next it finds a couple of elements and adds them to a collection. 
    //The elements in the collection are selected within the layout view.  Finally, the layout view is zoomed to the
    //extent of the selection.
    
    // Make sure the active pane is a layout view and then reference it
    if (LayoutView.Active != null)
    {
      LayoutView lytView = LayoutView.Active;
      //Reference the layout associated with the layout view
      Layout lyt = await QueuedTask.Run(() => lytView.Layout);
    
      //Find a couple of layout elements and add them to a collection
      Element map1 = lyt.FindElement("Map1 Map Frame");
      Element map2 = lyt.FindElement("Map2 Map Frame");
      List<Element> elmList = new List<Element>();
      elmList.Add(map1);
      elmList.Add(map2);
    
      //Set the selection on the layout view and zoom to the selected elements
      await QueuedTask.Run(() => lytView.SelectElements(elmList));
      await QueuedTask.Run(() => lytView.ZoomToSelectedElements());
    }
    LayoutViewClassExample2
    // Make sure the active pane is a layout view and then reference it
    if (LayoutView.Active != null)
    {
      LayoutView lytView = LayoutView.Active;
      //Reference the layout associated with the layout view
      Layout lyt = await QueuedTask.Run(() => lytView.Layout);
    
      //Find a couple of layout elements and add them to a collection
      Element map1 = lyt.FindElement("Map1 Map Frame");
      Element map2 = lyt.FindElement("Map2 Map Frame");
      List<Element> elmList = new List<Element>();
      elmList.Add(map1);
      elmList.Add(map2);
    
      //Set the selection on the layout view and zoom to the selected elements
      await QueuedTask.Run(() => lytView.SelectElements(elmList));
      await QueuedTask.Run(() => lytView.ZoomToSelectedElements());
      return true;
    }
    return false;
    Set element selection
    //Set the active layout view's selection to include 2 rectangle elements.
    
    //Reference the active view 
    LayoutView activeLayoutView = LayoutView.Active;
    if (activeLayoutView != null)
    {
    
      //Perform on the worker thread
      QueuedTask.Run(() =>
      {
    
        //Reference the layout
        Layout lyt = activeLayoutView.Layout;
    
        //Reference the two rectangle elements
        Element rec = lyt.FindElement("Rectangle");
        Element rec2 = lyt.FindElement("Rectangle 2");
    
        //Construct a list and add the elements
        List<Element> elmList = new List<Element>
        {
          rec,
          rec2
        };
    
        //Set the selection
        activeLayoutView.SelectElements(elmList);
      });
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also