# TextFieldCollection.Clear Method

> Removes all text fields from a Text Control document.

- **Product:** TX Text Control .NET for WPF
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 13.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 > TextFieldCollection.Clear Method
- **720 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/textfieldcollection/clear-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/textfieldcollection/clear-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/textfieldcollection/clear-method/llms-full.txt

---

### Description

Removes all text fields from a Text Control document.

### Syntax

```csharp
public void Clear(bool keepText);
```

```vbnet
Public Sub Clear(keepText As Boolean)
```

### Parameters

| Parameter | Description |
|---|---|
| keepText | If this parameter is set to true, all text fields are removed without deleting their texts. Otherwise, the texts are also deleted. |

### Examples

The following example works with text fields in the current document by using `TextFieldCollection.Clear`.

```csharp
textControl.Text = "Customer: Contoso Ltd.";
textControl.Select(10, 12);
TextFieldCollection textFieldCollection = textControl.TextFields;
textFieldCollection.Add(new ApplicationField(ApplicationFieldFormat.MSWord, "MERGEFIELD", "Customer name", new[] { "CustomerName" }) { ID = 100 });

if (textFieldCollection.Count > 0)
{
    textFieldCollection.Clear(true);
}
```

```vbnet
textControl.Text = "Customer: Contoso Ltd."
textControl.Select(10, 12)
Dim textFieldCollection As TextFieldCollection = textControl.TextFields
textFieldCollection.Add(New ApplicationField(ApplicationFieldFormat.MSWord, "MERGEFIELD", "Customer name", New String() { "CustomerName" }) With { .ID = 100 })

If textFieldCollection.Count > 0 Then
    textFieldCollection.Clear(True)
End If
```

---

## Nearby

- **Previous:** [TextFieldCollection.Add Method](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/textfieldcollection/add-method/llms-full.txt)
- **Next:** [TextFieldCollection.CopyTo Method](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/textfieldcollection/copyto-method/llms-full.txt)
