AutoCompleteBox CustomFilteringBehavior with Single SelectionMode

4 posts, 0 answers
  1. Toumir
    Toumir avatar
    3 posts
    Member since:
    May 2013

    Posted 12 Oct 2013 Link to this post

    I'm Interest for the AutoCompleteBox  Control but i have this issue:

    Ihave this CustomFilteringBehavior:

    public class CustomFilteringBehavior : FilteringBehavior
            public override System.Collections.Generic.IEnumerable<object> FindMatchingItems(string searchText, System.Collections.IList items, System.Collections.Generic.IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode)
                var searchTextToUpper = searchText.ToUpper();
                var matchingItems = items.OfType<Person>().
                    Where(x => x.FirstName.ToUpper().Contains(searchTextToUpper) || x.LastName.ToUpper().Contains(searchTextToUpper)
                    || (x.FirstName + " " + x.LastName).ToUpper().Contains(searchTextToUpper));
                return matchingItems.Where(x => !escapedItems.Contains(x));

    and in my main page i used this CustomFilteringBeahvior:

            <local:ViewModel x:Key="ViewModel" />
            <local:CustomFilteringBehavior x:Key="CustomFilteringBehavior" />
            <DataTemplate x:Key="CustomItemTemplate">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding FirstName}" />
                    <TextBlock Text=" " />
                    <TextBlock Text="{Binding LastName}" />
        <Grid x:Name="LayoutRoot" Background="White" DataContext="{StaticResource ViewModel}">
                <telerik:RadAutoCompleteBox ItemsSource="{Binding People}"
                                            FilteringBehavior="{StaticResource CustomFilteringBehavior}"
                                            DropDownItemTemplate="{StaticResource CustomItemTemplate}"
                                            BoxesItemTemplate="{StaticResource CustomItemTemplate}"
                                            AutoCompleteMode="Suggest" />

    when typing :

    in SelectionMode="Multiple" all works fine but
    in SelectionMode="Single" the result after selection is :

    is there any idea for this behavior ?

    Thank you in advance,
  2. Toumir
    Toumir avatar
    3 posts
    Member since:
    May 2013

    Posted 13 Oct 2013 Link to this post

    Where is the Telerik Team :-(
  3. Kalin
    Kalin avatar
    1283 posts

    Posted 14 Oct 2013 Link to this post

    Hi Toumir,

    When the AutoCompleteBox is in Single SelectectionMode it uses a TextBox to display the SelectedItem information as a text by calling its ToString method. So the most simple way to achieve the desired scenario is to override the ToString method in your Person class in order to return the full name of the person instead of the type of the object. Please check the code snippet below:

    public override string ToString()
        return this.FirstName + " " + this.LastName;

    Hope this will work for you. If you have any other questions let us know.

    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  4. Toumir
    Toumir avatar
    3 posts
    Member since:
    May 2013

    Posted 20 Oct 2013 Link to this post

    :-) Thank you for your answer, this is what I want

Back to Top