This is a migrated thread and some comments may be shown as answers.

AutoCompleteBox CustomFilteringBehavior with Single SelectionMode

3 Answers 44 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Toumir
Top achievements
Rank 1
Toumir asked on 12 Oct 2013, 10:37 AM
Hi,
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:

<UserControl.Resources>
         
        <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}" />
            </StackPanel>
        </DataTemplate>
         
    </UserControl.Resources>
 
    <Grid x:Name="LayoutRoot" Background="White" DataContext="{StaticResource ViewModel}">
        <StackPanel>
            <telerik:RadAutoCompleteBox ItemsSource="{Binding People}"
                                        FilteringBehavior="{StaticResource CustomFilteringBehavior}"
                                        DropDownItemTemplate="{StaticResource CustomItemTemplate}"
                                        BoxesItemTemplate="{StaticResource CustomItemTemplate}"
                                        SelectionMode="Single"
                                        AutoCompleteMode="Suggest" />
        </StackPanel>
    </Grid>

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,

3 Answers, 1 is accepted

Sort by
0
Toumir
Top achievements
Rank 1
answered on 14 Oct 2013, 03:57 AM
Where is the Telerik Team :-(
0
Kalin
Telerik team
answered on 14 Oct 2013, 12:06 PM
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.

Regards,
Kalin
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
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 >>
0
Toumir
Top achievements
Rank 1
answered on 20 Oct 2013, 09:19 AM
:-) Thank you for your answer, this is what I want

Tags
AutoCompleteBox
Asked by
Toumir
Top achievements
Rank 1
Answers by
Toumir
Top achievements
Rank 1
Kalin
Telerik team
Share this question
or