ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / IElementFactory Interface / CreateGroupElement Method
The parent element container
The collection of elements to be grouped (optional)
An element name (optional)
Select after create flag (default is true) (optional)
Additional element properties (optional)
Example

In This Topic
    CreateGroupElement Method (IElementFactory)
    In This Topic
    Create a group element from the input element collection and element properties.
    Syntax

    Parameters

    elementContainer
    The parent element container
    elements
    The collection of elements to be grouped (optional)
    elementName
    An element name (optional)
    select
    Select after create flag (default is true) (optional)
    groupElementInfo
    Additional element properties (optional)

    Return Value

    Remarks
    Only elements contained within the provided elementContainer will be added to the group element. If elements is null or an empty collection then an empty GroupElement will be created.
    Example
    Create_Empty_Group_Root
    //Create an empty group element at the root level of the contents pane.
    
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement emptyGroupAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout);
      //         emptyGroupAtRoot.SetName("Empty group at root");
      GroupElement emptyGroupAtRoot = ElementFactory.Instance.CreateGroupElement(layout, null, "Empty group at root");
    });
    Create_Empty_Group_Group
    //Create an empty group element at the root level of another group element.
    
    //Find an existing group element
    GroupElement existingGroupAtRoot = layout.FindElement("Empty group at root") as GroupElement;
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement emptyGroupInGroupAtRoot = LayoutElementFactory.Instance.CreateGroupElement(existingGroupAtRoot);
      //         emptyGroupInGroupAtRoot.SetName("Empty group in group at root");
      GroupElement emptyGroupInGroupAtRoot = ElementFactory.Instance.CreateGroupElement(
                                              existingGroupAtRoot, null, "Empty group in group at root");
    
    });
    Create_Group_With_Single_Element_Root
    //Create a group with a single element at the root level of the contents pane.
    
    //Find an existing element
    Element titleElm = layout.FindElement("Title") as Element;
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement groupWithSingleElementAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout, titleElm);
      //         groupWithSingleElementAtRoot.SetName("Group with single element at root"); 
      GroupElement groupWithSingleElementAtRoot = 
               ElementFactory.Instance.CreateGroupElement(layout, new List<Element>() { titleElm }, "Group with single element at root");
    });
    Create_Group_With_List_Elements_Root
    //Create a group with a list of elements at the root level of the contents pane.
    
    //Find an existing elements
    Element scaleBar = layout.FindElement("Scale Bar") as Element;
    Element northArrow = layout.FindElement("North Arrow") as Element;
    Element legend = layout.FindElement("Legend") as Element;
    
    //Build a list and add the elements
    List<Element> elmList = new List<Element>
    {
      scaleBar,
      northArrow,
      legend
    };
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //At 2.x - GroupElement groupWithListOfElementsAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout, elmList);
      //         groupWithListOfElementsAtRoot.SetName("Group with list of elements at root");
      GroupElement groupWithListOfElementsAtRoot = 
        ElementFactory.Instance.CreateGroupElement(layout, elmList, "Group with list of elements at root");
    });
    Create_Group_With_List_Element_Names_Root
    //Create a group using a list of element names at the root level of the contents pane.
    
    //Build list of element names
    var elmNameList = new[] { "Table Frame", "Chart Frame" };
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //GroupElement groupWithListOfElementNamesAtRoot = LayoutElementFactory.Instance.CreateGroupElement(layout, elmNameList);
      //groupWithListOfElementNamesAtRoot.SetName("Group with list of element names at root");
    
      //At 3.x use FindElements to retrieve the respective elements first
      var elems = layout.FindElements(elmNameList);
      GroupElement groupWithListOfElementNamesAtRoot =
        ElementFactory.Instance.CreateGroupElement(layout, elems, "Group with list of element names at root");
    });
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also