AutoComplete

RadListBox has full autocomplete support - while the control is focused, you can type certain keys and the listbox will select the relative match for the currently typed text.

The purpose of this tutorial is to show you how to configure the autocomplete feature.

Using TextSearchMode property

This enumeration property specifies whether the text search will be StartsWith/Contains and/or case sensitive. It provides the following entries:

  • Contains

  • ContainsCaseSensitive

  • StartsWith

  • StartsWithCaseSensitive

Using TypedText property

The TypedText property of RadListBox contains the currently typed text. It is updated as soon as the user types a new key for autocomplete.

Setting TextPath/TextBinding

In most of the cases you will have a RadListBox populated with a collection of business objects. If your data source is more complex and your data objects are not single values but rather more complicated classes that have multiple properties, you can specify which value you want to use for Autocomplete. To accomplish this you need to configure the TextPath/TextBinding property.

Let's have the RadListBox bound to "Customers" collection as explained in Binding to Object article:

radlistbox features autocomplete 010

Setting TextPath /TextBinding property will allow to use "Name" property of the Customer object for AutoComplete:

Setting TextPath

<telerik:RadListBox  Width="300" x:Name="radListBox1" 
ItemsSource="{Binding Customers}" 
ItemTemplate="{StaticResource ListBoxCustomTemplate}" 
TextPath="Name" /> 

Typing, for example "L" will select the corresponding item:

radlistbox features autocomplete 020

Note that if you have set DisplayMemberPath to a certain property and you want to use the same property for Autocomplete, you don't need to set TextPath/TextBinding.

Autocomplete always starts from the beginning, regardless of the selection.

Pressing Esc clears the current text for autocomplete.

Disable Autocomplete

By default the autocomplete feature of RadListBox is always enabled. In order to disable it, you need to set the RadListBox's IsTextSearchEnabled property to False.

Setting IsTextSearchEnabled

<telerik:RadListBox x:Name="radListBox" IsTextSearchEnabled="False"/> 

Setting IsTextSearchEnabled

radListBox.IsTextSearchEnabled = false; 

Using AutocompleteBehavior.AutoCompleteTimeout

The AutocompleteBehavior class exposes a static property named AutoCompleteTimeout which allows you to configure the autocomplete timeout. Use this property when you want to set the timeout after which the typed text for the autocomplete is reset. Its default value is 1 second.

Example 4: Setting AutocompleteBehavior.AutoCompleteTimeout

Telerik.Windows.Controls.Primitives.AutocompleteBehavior.AutoCompleteTimeout = TimeSpan.FromSeconds(2); 
Telerik.Windows.Controls.Primitives.AutocompleteBehavior.AutoCompleteTimeout = TimeSpan.FromSeconds(2) 
In this article