New to Telerik UI for WinForms? Download free 30-day trial

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.

private void Insert()
    this.radAutoCompleteBox1.Text = "USA;";
    this.radAutoCompleteBox1.CaretIndex = 0;

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

Figure 1: Inserting text.

WinForms RadAutoCompleteBox Inserting text

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

Using the AppendText method.

private void Append()
    this.radAutoCompleteBox1.Text = "IT Department;";
    this.radAutoCompleteBox1.AppendText("Marketing Team;");

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

Figure 2: The text is appended at the end.

WinForms RadAutoCompleteBox Text is Appended at the End

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

Using the Delete method.

private void DeleteText()
    this.radAutoCompleteBox1.Text = "Germany;USA;Brazil;Bulgaria;Croatia;Serbia;";
    this.radAutoCompleteBox1.Select(0, 8);

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

Figure 3: The firs word is deleted.

WinForms RadAutoCompleteBox The Firs Word Deleted

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.

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

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

In this article