Selection

The purpose of this article is to show you the basic properties exposed by the RadAutoCompleteBox for working with selection.

SelectionMode

The RadAutoCompleteBox control provides two selection modes, which allow you to manipulate the type of selection. This is controlled by the SelectionMode enumeration property which has the following values:

  • Multiple: Multiple items can be added to the selection. (default value)

  • Single: Only one item can be selected at a time.

SelectedItem and SelectedItems

RadAutoCompleteBox exposes the SelectedItem and SelectedItems properties in order to grant you access to the selected item in the items of the control.

The SelectedItem property corresponds to the item the user has selected when SelectionMode is Single.

SelectedItems is a collection of items containing all selected items in the control when SelectionMode is set to Multiple.

The SelectedItems collection will always contain a single item when SelectionMode is set to Single and you change the selected item. When in Multiple selection mode, SelectedItem will be set to the first item added to the selected items that is still included in the selection.

Example 1 demonstrates how to get ahold of the selected items and also determine which item was selected first when in Multiple selection mode.

Example 1: Working with SelectedItem and SelectedItems

private void AutoComplete_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
    var selectedCountries = autoComplete.SelectedItems; 
    var firstSelectedCountry = autoComplete.SelectedItem as Country; 
} 
Private Sub AutoComplete_SelectionChanged(ByVal sender As Object, ByVal e As SelectionChangedEventArgs) 
    Dim selectedCountries = autoComplete.SelectedItems 
    Dim firstSelectedCountry = TryCast(autoComplete.SelectedItem, Country) 
End Sub 

See Also

In this article