RadAutoComplete throw null exception

4 posts, 0 answers
  1. Safak
    Safak avatar
    10 posts
    Member since:
    Mar 2016

    Posted 29 Dec 2017 Link to this post

    Hi,

     

    Changing ItemsSource property dynamically then focussing input entry throws null exception.

      autoComplete = new RadAutoComplete()
                {
                    ItemsSource = RecordedItems,
                    NoResultsMessage = "",
                    TextSearchPath = "Name",
                    ShowSuggestionView = true,
                    SuggestionViewHeight = RecordedItems.Count * 40,
                    CompletionMode = Telerik.XamarinForms.Input.AutoComplete.CompletionMode.Contains,
                    DisplayMode = Telerik.XamarinForms.Input.AutoComplete.SuggestionsDisplayMode.Tokens,
                    SuggestMode = Telerik.XamarinForms.Input.AutoComplete.SuggestMode.SuggestAppend,
                    SuggestionItemTemplate = new DataTemplate(() =>
                    {
                        var grid = new Grid();
                        grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) });
                        var lbl = new Label()
                        {
                            Margin = new Thickness(5),
                            FontSize = 24,
                            TextColor = Color.Black
                        };
                        lbl.SetBinding(Label.TextProperty, "Item.Name");
                        grid.Children.Add(lbl);
                        return grid;
                    })
                };

     

    System.NullReferenceException: Object reference not set to an instance of an object.
       at Telerik.Core.BindingExpressionHelper.<>c__DisplayClass3_0.<CreateGetValueFunc>b__1(Object item)
       at Telerik.UI.Xaml.Controls.Input.AutoCompleteBox.TextSearchProvider.GetFilterKey(Object item)
       at Telerik.UI.Xaml.Controls.Input.AutoCompleteBox.ContainsTextSearchProvider.BuildFilteredItems(Boolean clear)
       at Telerik.UI.Xaml.Controls.Input.AutoCompleteBox.ContainsTextSearchProvider.Input(Int32 start, Int32 sele

     

  2. Ves
    Admin
    Ves avatar
    2926 posts

    Posted 02 Jan 2018 Link to this post

    Hi Safak,

    I can confirm that there is a problem when using complex objects i.e. the items in the source contain other items whose properties are used for search. While we investigate it, you can use the following workaround -- use a projected items source, containing only the innermost objects. In this specific case, something like this should do the trick:

    var autoComplete = new RadAutoComplete()
                {
                    ItemsSource = RecordedItems.Select(recItem => recItem.Item),
    ....................

    Where Item is the name of the property of the outer object. I hope this helps.

    Best regards,
    Ves
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Safak
    Safak avatar
    10 posts
    Member since:
    Mar 2016

    Posted 05 Jan 2018 in reply to Ves Link to this post

    Hi Ves,

    Thank you for your advise. It's working on a simpler object.

    One more questions; 

    How can i set selected tokens dynamicly? 

    Thank you,

    Best regards

  4. Safak
    Safak avatar
    10 posts
    Member since:
    Mar 2016

    Posted 05 Jan 2018 Link to this post

    Found the answer https://www.telerik.com/forums/set-selected-items
Back to Top