# Text Editing

The editing point is determined by the caret position and selection in **RadAutoCompleteBox**. The editing position is visible only if the control is focused.

You can insert text programmatically at concrete position by using the **Insert** method. In this case, the text is inserted at the position determined by the **SelectionStart** property. If the **SelectionLength** property is greater than zero, the inserted text replaces the selected text.

#### Using the Insert method.

```C#
private void Insert()
{
    this.radAutoCompleteBox1.Text = "USA;";
    this.radAutoCompleteBox1.CaretIndex = 0;
    this.radAutoCompleteBox1.Insert("Canada;");
}
```

```VB.NET
Private Sub Insert()
    Me.RadAutoCompleteBox1.Text = "USA;"
    Me.RadAutoCompleteBox1.CaretIndex = 0
    Me.RadAutoCompleteBox1.Insert("Canada;")
End Sub
```

> caption Figure 1: Inserting text.

![WinForms RadAutoCompleteBox Inserting text](https://www.telerik.com/products/winforms/documentation/assets/82e5ce545da57a32b383b247fd624b9a/editors-autocompletebox-text-editing001.png)

Alternatively, you can insert text at the end of the **RadAutoCompleteBox** content by using the **AppendText** method:

#### Using the AppendText method.

```C#
private void Append()
{
    this.radAutoCompleteBox1.Text = "IT Department;";
    this.radAutoCompleteBox1.AppendText("Marketing Team;");
}
```

```VB.NET
Private Sub Append()
    Me.RadAutoCompleteBox1.Text = "IT Department;"
    Me.RadAutoCompleteBox1.AppendText("Marketing Team;")
End Sub
```

> caption Figure 2: The text is appended at the end.

![WinForms RadAutoCompleteBox Text is Appended at the End](https://www.telerik.com/products/winforms/documentation/assets/dc5242fe2a0fa094af783534ccc3f95d/editors-autocompletebox-text-editing002.png)

You can delete the selected text or character at the caret position by using the **Delete** method:

#### Using the Delete method.

```C#
private void DeleteText()
{
    this.radAutoCompleteBox1.Text = "Germany;USA;Brazil;Bulgaria;Croatia;Serbia;";
    this.radAutoCompleteBox1.Select(0, 8);
    this.radAutoCompleteBox1.Delete();
}
```

```VB.NET
Private Sub DeleteText()
    Me.RadAutoCompleteBox1.Text = "Germany;USA;Brazil;Bulgaria;Croatia;Serbia;"
    Me.RadAutoCompleteBox1.[Select](0, 8)
    Me.RadAutoCompleteBox1.Delete()
End Sub
```

> caption Figure 3: The firs word is deleted.

![WinForms RadAutoCompleteBox The Firs Word Deleted](https://www.telerik.com/products/winforms/documentation/assets/5beba6a8dabf97e8770505dffbe52d45/editors-autocompletebox-text-editing003.png)

Each editing operation raises the **TextChanging** and **TextChanged** events. Notice that you can prevent successful finishing of operation by subscribing to the **TextChanging** event:

#### Prevent deleting a tokenized text blocks in RadAutoCompleteBox.

```C#
void radAutoCompleteBox1_TextChanging(object sender, Telerik.WinControls.TextChangingEventArgs e)
{
    e.Cancel = string.IsNullOrEmpty(e.NewValue) && e.OldValue.Contains(this.radAutoCompleteBox1.Delimiter.ToString());
}
```

```VB.NET
Private Sub radAutoCompleteBox1_TextChanging(sender As Object, e As Telerik.WinControls.TextChangingEventArgs)
    e.Cancel = String.IsNullOrEmpty(e.NewValue) AndAlso e.OldValue.Contains(Me.RadAutoCompleteBox1.Delimiter.ToString())
End Sub
```

The code above prevents deleting a tokenized text blocks in RadAutoCompleteBox.

## See Also

* [Caret Positioning and Selection](https://www.telerik.com/products/winforms/documentation/controls/editors/autocompletebox/caret-positioning-and-selection)
* [Creating Custom Blocks](https://www.telerik.com/products/winforms/documentation/controls/editors/autocompletebox/creating-custom-blocks)
* [Element Structure and Document Object Model](https://www.telerik.com/products/winforms/documentation/controls/editors/autocompletebox/element-structure-and-document-object-model)
* [Properties and Events](https://www.telerik.com/products/winforms/documentation/controls/editors/autocompletebox/customizing-appearance/formatting-blocks)
* [Auto-Complete](https://www.telerik.com/products/winforms/documentation/controls/editors/autocompletebox/auto-complete)
