New to Telerik UI for WinFormsStart a free 30-day trial

Text Editing

Updated over 6 months ago

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;");
}

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.

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

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.

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

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.

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

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

See Also

In this article
See Also
Not finding the help you need?
Contact Support