ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / ElementFactory Class / 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 for the group element (optional)
Example

In This Topic
    CreateGroupElement Method (ElementFactory)
    In This Topic
    Create a group element from the input element collection and element properties. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Function CreateGroupElement( _
       ByVal elementContainer As IElementContainer, _
       Optional ByVal elements As IEnumerable(Of Element), _
       Optional ByVal elementName As String, _
       Optional ByVal select As Boolean, _
       Optional ByVal groupElementInfo As ElementInfo _
    ) As GroupElement

    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 for the group element (optional)

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    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
    Creating empty group elements
    {
      //Create an empty group element at the root level of the contents pane
      //Note: Must be on QueuedTask.Run
    
      //container is IElementContainer - GroupLayer or Layout
      GroupElement grp1 = ElementFactory.Instance.CreateGroupElement(
                            layout, null, "Group");
      // *** or ***
      //Create a group element inside another group element
    
      //Find an existing group element
      //container is IElementContainer - GroupLayer or Layout
      GroupElement existingGroup = layout.FindElement("Group") as GroupElement;
    
      //Create on worker thread
      GroupElement grp2 = ElementFactory.Instance.CreateGroupElement(
          existingGroup, null, "Group in Group");
    }
    Create a group element with elements
    {
      //Create a group with a list of elements at the root level of the contents pane.
    
      //Find an existing elements
      //container is IElementContainer - GroupLayer or Layout
      var elem1 = layout.FindElement("Polygon 1");
      var elem2 = layout.FindElement("Bezier Text");
      var elem3 = layout.FindElement("Cloud Shape 2");
    
      //Construct a list and add the elements
      var elmList = new List<Element>
      {
        elem1,
        elem2,
        elem3
      };
      //Note: Must be on QueuedTask.Run
    
      GroupElement groupWithListOfElementsAtRoot =
                ElementFactory.Instance.CreateGroupElement(
                         layout, elmList, "Group with list of elements at root");
      // *** or ***
    
      //Create a group using a list of element names at the root level of the contents pane.
    
      //List of element names
      var elmNameList = new[] { "Para Text1", "Line 3" };
    
      //Note: Must be on QueuedTask.Run
    
      var elemToGroup = layout.FindElements(elmNameList);
      GroupElement groupWithListOfElementNamesAtRoot =
            ElementFactory.Instance.CreateGroupElement(
                 layout, elemToGroup, "Group with list of element names at root");
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also