ArcGIS Pro 3.7 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / Layout Class / UnGroupElements Method
The group elements whose elements are to be ungrouped
Example

In This Topic
    UnGroupElements Method (Layout)
    In This Topic
    Ungroup the elements contained in 'groups'. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Sub UnGroupElements( _
       ByVal groups As IEnumerable(Of GroupElement) _
    ) 
    public void UnGroupElements( 
       IEnumerable<GroupElement> groups
    )

    Parameters

    groups
    The group elements whose elements are to be ungrouped
    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    groups cannot be null or empty
    elements must belong to layout 'URI'
    element parents must be the same and non-null
    Remarks
    All group elements in the input collection must have the same parent.
    Example
    Un-Group Graphic Elements
    {
      //Note: Must be on QueuedTask.Run
      var selectedElements = layout.GetSelectedElements().ToList();
      if (selectedElements?.Count == 0)//must be at least 1.
        return;
      var elementsToUnGroup = new List<GroupElement>();
      //All selected elements should be grouped elements.
      if (selectedElements.Count() == selectedElements.OfType<GroupElement>().Count())
      {
        //Convert to a GroupElement list.
        elementsToUnGroup = selectedElements.ConvertAll(x => (GroupElement)x);
      }
      if (elementsToUnGroup.Count() == 0)
        return;
      //UnGroup many grouped elements
      layout.UnGroupElements(elementsToUnGroup);
      //Ungroup one grouped element
      layout.UnGroupElement(elementsToUnGroup.FirstOrDefault());
    }
    Requirements

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

    ArcGIS Pro version: 3.0 or higher.
    See Also