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;
}