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

RadAutoComplete throw null exception

3 Answers 126 Views
AutoComplete
This is a migrated thread and some comments may be shown as answers.
Safak
Top achievements
Rank 1
Safak asked on 29 Dec 2017, 09:10 AM

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

 

3 Answers, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 02 Jan 2018, 12:54 PM
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
0
Safak
Top achievements
Rank 1
answered on 05 Jan 2018, 10:27 AM

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

0
Safak
Top achievements
Rank 1
answered on 05 Jan 2018, 10:30 AM
Found the answer https://www.telerik.com/forums/set-selected-items
Tags
AutoComplete
Asked by
Safak
Top achievements
Rank 1
Answers by
Ves
Telerik team
Safak
Top achievements
Rank 1
Share this question
or