Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

ShapeCollection.Flatten() Method

Converts a shape collection into a flattened collection that contains all drawing objects in the document, including items of shape groups and canvases.

Namespace: DevExpress.XtraRichEdit.API.Native

Assembly: DevExpress.RichEdit.v24.2.Core.dll

NuGet Package: DevExpress.RichEdit.Core

#Declaration

#Returns

Type Description
IEnumerable<DrawingObject>

A flattened collection of drawing objects in the document.

#Remarks

The ShapeCollection stores each shape group or drawing canvas as a single object and does not include their items. You need to use the following properties to obtain their elements:

The Flatten method recursively iterates through the shape collection (its groups and canvases) and collects all drawing objects stored in the document. You can filter the collection by Type to retrieve specific shapes.

The example below shows how to split all shape groups in the document (including nested groups):

using System.Linq;
// ...

Document document = wordProcessor.Document;
List<DrawingObject> groups = document.Shapes.Flatten()
    .Where(x => x.Type == ShapeType.Group)
    .ToList();
for (int i = groups.Count - 1; i >= 0; i--)
{
    groups[i].GroupItems.Ungroup();
}
See Also