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

RadAutoCompleteBox with dynamic ItemSource problem.

2 Answers 102 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
Bryan
Top achievements
Rank 1
Bryan asked on 18 Feb 2019, 05:52 PM

I have an RadAutoCompleteBox with a dynamic ItemSource that works some places and not others.  In the setter for the SearchText I run a search and populate the ItemSource.  In the box I'm working on now, the ItemSource's ObservableCollection is giving me "Exception thrown: 'System.ArgumentException' in System.Core.dll" when i try and add item to it. This method works many places elsewhere, and If i manually set the SearchText elsewhere the offending code runs without error. Any help would be greatly appreciated.

Here's the XAML:

<telerik:RadAutoCompleteBox 

    Grid.Column="2" Grid.Row="3"
    x:Name="AutoCompleteBoxMakeModel"
    ItemsSource="{Binding MakeModelCollection}"
    SearchText="{Binding MakeModelTerm, Mode=TwoWay}"
    SelectedItem="{Binding SelectedMakeModel, Mode=TwoWay}"
    SelectionMode="Single"
    HorizontalAlignment="Left" 
    TextSearchPath="Display"
    TextSearchMode="Contains"
    AutoCompleteMode="Suggest"
    IsDropDownOpen="{Binding IsMakeModelDropDownOpen, Mode=TwoWay}"
    DropDownItemTemplate="{StaticResource MakeModelSearchTemplate}"
    DropDownWidth="300"
    VerticalAlignment="Top" Width="275"  Height="25" Margin="0,3,0,0" >
    <telerik:StyleManager.Theme>
        <telerik:VisualStudio2013Theme/>
    </telerik:StyleManager.Theme>
</telerik:RadAutoCompleteBox>

 

And here's the offending code:

private string makeModelTerm;
public string MakeModelTerm
{
    get { return makeModelTerm; }
    set
    {
        if (makeModelTerm == value)
        {
            return;
        }
        makeModelTerm = value;
        RaisePropertyChanged("MakeModelTerm");
        if (value.Length > 2)
        {
            SearchMakeModel(value);
        }
    }
}

private void SearchMakeModel(string value)
{
    LookUpRepository er = new LookUpRepository();
    var list = er.SearchMakeModel(value);
    MakeModelCollection.Clear();
    list.ForEach(MakeModelCollection.Add); // This triggers the System.ArgumentException on each value in list
    this.IsMakeModelDropDownOpen = true;
}

2 Answers, 1 is accepted

Sort by
0
Accepted
Vladimir Stoyanov
Telerik team
answered on 21 Feb 2019, 02:18 PM
Hello Bryan,

Thank you for the provided sample code. 

I tried to reproduce the described exception on my end, however I was not able to do so. I created a sample application based on the provided code and replaced/guessed the parts of the code that were not available and I am attaching it for your reference.

May I ask you to check out the sample project and see how it differs from the setup on your end? Should you need any further assistance, may I kindly ask you to modify the sample project in order to reproduce the observed on your end behavior and send it back? This way I will be able to investigate the scenario on my end and better assist you. 

I am looking forward to your reply.

Regards,
Vladimir Stoyanov
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Bryan
Top achievements
Rank 1
answered on 21 Feb 2019, 02:49 PM

Thanks!

 

I realized that my TextSearchPath had a typo in it which was causing the exception.

Tags
AutoCompleteBox
Asked by
Bryan
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Bryan
Top achievements
Rank 1
Share this question
or