# SubTextPartCollection Class

> Contains all subtextparts in the main text or another main part of a document. It is a collection of objects of the type SubTextPart. A collection object can be obtained with the TextControl.SubTextParts, the HeaderFooter.SubTextParts or the TextFrame.SubTextParts property. The SubTextPartCollection class implements the IEnumerable and the ICollection interfaces. The text of each main part of the document, which are the main text, a header or footer or a textframe, can be divided in further parts, called subtextparts. A subtextpart must be a selectable part of the document. It can immediately follow its previous textpart. The position between two textparts belongs to the following textpart. Subtextparts can be nested. A nested textpart must be smaller than its outer textpart. A nested textpart can start or end at the same position as its outer textpart, but a nested textpart cannot have the same length as its outer textpart. To insert a nested textpart its outer textpart must be inserted first. A textpart cannot have a length of zero. When the last character of a textpart is deleted, the textpart itself is also deleted.

- **Product:** TX Text Control .NET for Windows Forms
- **Section:** Reference
- **Kind:** Class
- **Introduced:** 23.0
- **Namespace:** `TXTextControl`
- **Package:** `TXTextControl.TextControl.WinForms.SDK` (assembly `TXTextControl.dll`, from the private NuGet feed or Text Control Offline Packages)
- **.NET Framework:** reference `TXTextControl.dll` from the setup
- **Implements:** `System.Collections.ICollection`, `System.Collections.IEnumerable`
- **Path:** TX Text Control .NET for Windows Forms > Reference > TXTextControl > SubTextPartCollection Class
- **1309 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/llms-full.txt

---

### Description

Contains all subtextparts in the main text or another main part of a document. It is a collection of objects of the type [SubTextPart](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpart/llms-full.txt). A collection object can be obtained with the [TextControl.SubTextParts](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textcontrol/subtextparts-property/llms-full.txt), the [HeaderFooter.SubTextParts](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/headerfooter/subtextparts-property/llms-full.txt) or the [TextFrame.SubTextParts](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/textframe/subtextparts-property/llms-full.txt) property. The SubTextPartCollection class implements the IEnumerable and the ICollection interfaces. The text of each main part of the document, which are the main text, a header or footer or a textframe, can be divided in further parts, called subtextparts. A subtextpart must be a selectable part of the document. It can immediately follow its previous textpart. The position between two textparts belongs to the following textpart. Subtextparts can be nested. A nested textpart must be smaller than its outer textpart. A nested textpart can start or end at the same position as its outer textpart, but a nested textpart cannot have the same length as its outer textpart. To insert a nested textpart its outer textpart must be inserted first. A textpart cannot have a length of zero. When the last character of a textpart is deleted, the textpart itself is also deleted.

### Syntax

```csharp
public sealed class SubTextPartCollection : ICollection, IEnumerable
```

```vbnet
Public NotInheritable Class SubTextPartCollection
    Implements ICollection, IEnumerable
```

### Examples

The following example works with sub text parts in the current document.

```csharp
textControl.Text = "Customer: Contoso Ltd.";
textControl.Select(10, 12);
SubTextPartCollection subTextPartCollection = textControl.SubTextParts;
subTextPartCollection.Add(new SubTextPart("CustomerName", 10));
```

```vbnet
textControl.Text = "Customer: Contoso Ltd."
textControl.Select(10, 12)
Dim subTextPartCollection As SubTextPartCollection = textControl.SubTextParts
subTextPartCollection.Add(New SubTextPart("CustomerName", 10))
```

---

## In This Section

- [SubTextPartCollection.Add Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/add-method/llms-full.txt): Adds a new subtextpart to the document. Its position is defined through the SubTextPart.Start and SubTextPart.Length properties. If the subtextpart's length is zero, the current text selection is used to define the position.
- [SubTextPartCollection.AddResult Enumeration](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/addresult-enumeration/llms-full.txt): Specifies the result when a subtextpart has been added to the document.
- [SubTextPartCollection.CopyTo Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/copyto-method/llms-full.txt): Copies the elements of the collection to an array, starting at a particular index.
- [SubTextPartCollection.Count Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/count-property/llms-full.txt): Gets the number of elements contained in the collection.
- [SubTextPartCollection.GetEnumerator Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/getenumerator-method/llms-full.txt): Returns an enumerator that can be used to iterate through the collection.
- [SubTextPartCollection.GetItem Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/getitem-method/llms-full.txt): Gets a particular subtextpart from the collection.
- [SubTextPartCollection.IsSynchronized Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/issynchronized-property/llms-full.txt): Returns true if the collection is designed to be thread safe, otherwise, it returns false.
- [SubTextPartCollection.Item Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/item-property/llms-full.txt): Gets the subtextpart with the specified number from the collection. The number must be between 1 and Count. In C# this property is the indexer for the SubTextPartCollection class.
- [SubTextPartCollection.Remove Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/remove-method/llms-full.txt): Removes a subtextpart from the collection including all its nested subtextparts.
- [SubTextPartCollection.SyncRoot Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/syncroot-property/llms-full.txt): Gets an object that can be used to synchronize access to the collection.

---

## Nearby

- **Previous:** [SubTextPart.Text Property](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpart/text-property/llms-full.txt)
- **Next:** [SubTextPartCollection.Add Method](https://docs.textcontrol.com/tx-text-control-dotnet-winforms/reference/txtextcontrol/subtextpartcollection/add-method/llms-full.txt)
