![](dotnetdiagramimages/image1103.png)
public class GroupElement : Element, ArcGIS.Desktop.Mapping.IElement, ArcGIS.Desktop.Mapping.IElementContainer, System.ComponentModel.INotifyPropertyChanged, System.IComparable, System.IDisposable, System.IEquatable<Element>
Public Class GroupElement Inherits Element Implements ArcGIS.Desktop.Mapping.IElement, ArcGIS.Desktop.Mapping.IElementContainer, System.ComponentModel.INotifyPropertyChanged, System.IComparable, System.IDisposable, System.IEquatable(Of Element)
It is possible that group elements can be nested in another group element. If the element container is a Layout then the element gets added to the root level of the layout TOC at the top most position. If the element container is a GroupElement then it gets added to the group at the topmost position.
The FindElement method will also find elements nested in a group element.
If you want to work with all the elements within a group element, use the Elements property to return the collection of elements in a group element.
//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 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 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 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 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"); });
//Create an empty group element at the root level of the contents pane //Create on worker thread await QueuedTask.Run(() => { //At 2.x - GroupElement grp1 = // LayoutElementFactory.Instance.CreateGroupElement(layout); // grp1.SetName("Group"); //container is IElementContainer - GroupLayer or Layout GroupElement grp1 = ElementFactory.Instance.CreateGroupElement( container, null, "Group"); }); // *** or *** //Create a group element inside another group element //Find an existing group element //container is IElementContainer - GroupLayer or Layout GroupElement existingGroup = container.FindElement("Group") as GroupElement; //Create on worker thread await QueuedTask.Run(() => { //At 2.x - GroupElement grp2 = // LayoutElementFactory.Instance.CreateGroupElement(existingGroup); // grp2.SetName("Group in Group"); GroupElement grp2 = ElementFactory.Instance.CreateGroupElement( existingGroup, null, "Group in Group"); });
//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 = container.FindElement("Polygon 1"); var elem2 = container.FindElement("Bezier Text"); var elem3 = container.FindElement("Cloud Shape 2"); //Construct a list and add the elements var elmList = new List<Element> { elem1, elem2, elem3 }; //Perform 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( container, 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" }; //Perform on the worker thread await QueuedTask.Run(() => { //At 2.x - GroupElement groupWithListOfElementNamesAtRoot = // LayoutElementFactory.Instance.CreateGroupElement(layout, elmNameList); // groupWithListOfElementNamesAtRoot.SetName( // "Group with list of element names at root"); //At 3.x, use the names to find the relevant elements first //container is IElementContainer - GroupLayer or Layout var elems = container.FindElements(elmNameList); GroupElement groupWithListOfElementNamesAtRoot = ElementFactory.Instance.CreateGroupElement( container, elems, "Group with list of element names at root"); });
System.Object
ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
ArcGIS.Desktop.Layouts.Element
ArcGIS.Desktop.Layouts.GroupElement
ArcGIS.Desktop.Reports.ReportSectionElement
Target Platforms: Windows 11, Windows 10, Windows 8.1