How to ungroup GroupElement created in Layout

951
1
Jump to solution
11-05-2020 07:33 AM
MyriamFischer
New Contributor II

I created a GroupElement with layout elements such as text, legend, scalebar to find the bounds of all graphic elements except the map frame. 

GroupElement allElements = LayoutElementFactory.Instance.CreateGroupElement(layout, layout.Elements);

I see this Element in the content pane. Now I just want to ungroup this GroupElement but I just can't find a way to do it by code.

There is the function to ungroup a GraphicsLayer in the map but this is not a graphics layer in the map, it is a GroupElement in the Layout.

Please help me.

Thanks 

Myriam

0 Kudos
1 Solution

Accepted Solutions
MyriamFischer
New Contributor II

For anyone who is also thinking in the wrong direction, I found the solution: The elements have to be "ungrouped" in the TOC. First they have to be reversed to maintain the same order in the TOC as before they were grouped.

if (group != null)
{
group.Elements.Reverse();
foreach (var item in group.Elements)
{
item.SetTOCPositionAbsolute(layout, true);
}

var groupToDelete = layout.FindElement(group.Name);
layout.DeleteElement(groupToDelete);
}

View solution in original post

0 Kudos
1 Reply
MyriamFischer
New Contributor II

For anyone who is also thinking in the wrong direction, I found the solution: The elements have to be "ungrouped" in the TOC. First they have to be reversed to maintain the same order in the TOC as before they were grouped.

if (group != null)
{
group.Elements.Reverse();
foreach (var item in group.Elements)
{
item.SetTOCPositionAbsolute(layout, true);
}

var groupToDelete = layout.FindElement(group.Name);
layout.DeleteElement(groupToDelete);
}

0 Kudos