ArcGIS Pro 3.0 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / GraphicsLayerExtensions Class / GroupElements Method
The elements to be grouped.
Example

In This Topic
    GroupElements Method (GraphicsLayerExtensions)
    In This Topic
    Group the collection of elements. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Shared Function GroupElements( _
       ByVal graphicsLayer As GraphicsLayer, _
       ByVal elements As IEnumerable(Of Element) _
    ) As GroupElement

    Parameters

    graphicsLayer
    elements
    The elements to be grouped.

    Return Value

    ArcGIS.Desktop.Layouts.GroupElement containing the grouped elements
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    elements cannot be null or empty
    elements must belong to graphicsLayer
    elements must be group elements or graphic elements
    element parents must be the same and non-null
    Map has reached maximum graphics count limit of 4000 elements. One or more elements cannot be created.
    Map has reached maximum graphics size limit of 10 MB. One or more elements cannot be created.
    Remarks
    All group elements in the input collection must have the same parent.
    Example
    Group Graphic Elements
    var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList()
                        .OfType<ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault();
    if (graphicsLayer == null)
      return;
    
    var elemsToGroup = graphicsLayer.GetSelectedElements();
    //Note: run within the QueuedTask
    //group  elements
    var groupElement = graphicsLayer.GroupElements(elemsToGroup);
    Requirements

    Target Platforms: Windows 11, Windows 10, Windows 8.1

    See Also