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

empty behavior

2 Answers 129 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
David Ocasio asked on 05 Nov 2012, 02:59 PM
the typical behavior with this control when there is no search text
is to hide the drop down

is there a way to change this
I would prefer in some cases to show all values when they have not typed anything.

thanks
dco

2 Answers, 1 is accepted

Sort by
0
Accepted
Ivo
Telerik team
answered on 08 Nov 2012, 10:06 AM
Hello David,

This can be achieved by writing a few lines of custom code.

First of all you will have to handle the GotFocus event of the RadAutoCompleteBox and execute its Populate method giving the control's SearchText as parameter. After this you will have to create a custom filtering behavior derived from the FilteringBehavior class and override the FindMatchingItems method. Into this method you have to return all items if the string is null or empty. Here is sample code:
private void AutoCompleteBox_GotFocus(object sender, RoutedEventArgs e)
{
    var autoComplete = (RadAutoCompleteBox)sender;
    autoComplete.Populate(autoComplete.SearchText);
}

public class CustomFilteringBehavior : FilteringBehavior
{
    public override IEnumerable<object> FindMatchingItems(string searchText, System.Collections.IList items, IEnumerable<object> escapedItems, string textSearchPath, TextSearchMode textSearchMode)
    {
        if (string.IsNullOrEmpty(searchText))
        {
            return items.OfType<object>().Where(x => !escapedItems.Contains(x));
        }
        else
        {
            return base.FindMatchingItems(searchText, items, escapedItems, textSearchPath, textSearchMode);
        }
    }
}

Greetings,
Ivo
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 08 Nov 2012, 12:42 PM
thanks ivo
Tags
AutoCompleteBox
Asked by
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Ivo
Telerik team
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or