empty behavior

3 posts, 1 answers
  1. David Ocasio
    David Ocasio avatar
    147 posts
    Member since:
    Nov 2009

    Posted 05 Nov 2012 Link to this post

    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. Answer
    Ivo
    Admin
    Ivo avatar
    390 posts

    Posted 08 Nov 2012 Link to this post

    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.

  3. DevCraft banner
  4. David Ocasio
    David Ocasio avatar
    147 posts
    Member since:
    Nov 2009

    Posted 08 Nov 2012 Link to this post

    thanks ivo
Back to Top