I have combobox which is correctly populated with some field ID when button is clicked.
private void Button_Click(object sender, RoutedEventArgs e)
{
results.Items.Add(ID);
}
Now I want when I change some value to delete previous value (or values in case I have multiple values in combobox) but I am always getting exception (if some value is already selected in Combo Box) I tried to add in that method on the top this:
results.Items.Clear();
and I tried this:
for (int i = 0; i < results.Items.Count; i++)
{
results.Items.RemoveAt(i);
i--;
}
But always getting exception:
System.ArgumentException: Value does not fall within the expected range. at MS.Internal.XcpImports.MethodEx(IntPtr ptr, String name, CValue[] cvData) at MS.Internal.XcpImports.MethodPack(IntPtr objectPtr, String methodName, Object[] rawData) at MS.Internal.XcpImports.Collection_Add[T](PresentationFrameworkCollection'1 collection, Object value) at System.Windows.PresentationFrameworkCollection'1.AddImpl(Object value) at System.Windows.Controls.ItemCollection.AddImpl(Object value) at System.Windows.Controls.ItemCollection.AddInternal(Object value) at System.Windows.PresentationFrameworkCollection'1.Add(T value) at SXPCreateIncident3.SilverlightControl1.results_SelectionChanged(Object sender, SelectionChangedEventArgs e) at System.Windows.Controls.Primitives.Selector.OnSelectionChanged(SelectionChangedEventArg
If I don't have this part with Clear (Remove) then combobox has more elements on every button Click but I need to clear previous content when button is clicked.