# SubTextPartCollection.Remove Method

> Removes a subtextpart from the collection including all its nested subtextparts.

- **Product:** TX Text Control .NET for WPF
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 23.0
- **Namespace:** `TXTextControl`
- **Package:** `TXTextControl.TextControl.WPF.SDK` (assembly `TXTextControl.dll`, from the private NuGet feed or Text Control Offline Packages)
- **.NET Framework:** reference `TXTextControl.dll` from the setup
- **Path:** TX Text Control .NET for WPF > Reference > TXTextControl > SubTextPartCollection.Remove Method
- **744 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/subtextpartcollection/remove-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/subtextpartcollection/remove-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/subtextpartcollection/remove-method/llms-full.txt

---

### Description

Removes a subtextpart from the collection including all its nested subtextparts.

### Syntax

```csharp
public bool Remove(SubTextPart subTextPart, bool keepText, bool keepNested);
```

```vbnet
Public Function Remove(subTextPart As SubTextPart, keepText As Boolean, keepNested As Boolean) As Boolean
```

### Parameters

| Parameter | Description |
|---|---|
| subTextPart | Specifies the subtextpart to remove. |
| keepText | If this parameter is set to true, the subtextpart is removed without deleting its visible text. Otherwise, the visible text is also removed. |
| keepNested | If this parameter is set to true, nested subtextparts are preserved. When the keepText parameter is set to false, this parameter is ignored. |

### Return Value

The return value is true, if the textpart could be removed. Otherwise, it is false.

### Examples

The following example removes a region marker while retaining both its text and nested regions.

```csharp
textControl.Text = "Customer: Contoso Ltd.";
textControl.Select(10, 12);
SubTextPartCollection parts = textControl.SubTextParts;
SubTextPart customer = new("CustomerName", 10) { Data = @"{""category"":""customer""}" };
parts.Add(customer);
parts.Remove(customer, true, true);
```

```vbnet
textControl.Text = "Customer: Contoso Ltd."
textControl.Select(10, 12)
Dim parts As SubTextPartCollection = textControl.SubTextParts
Dim customer As New SubTextPart("CustomerName", 10) With { .Data = "{""category"":""customer""}" }
parts.Add(customer)
parts.Remove(customer, True, True)
```

---

## Nearby

- **Previous:** [SubTextPartCollection.Item Property](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/subtextpartcollection/item-property/llms-full.txt)
- **Next:** [SubTextPartCollection.SyncRoot Property](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/subtextpartcollection/syncroot-property/llms-full.txt)
