I implemented the row reordering example from the Silverlight demos on a multi-select grid (SelectionMode = Extended), and want to clear the selected items after the drop occurs. I tried calling grid.UnselectAll(), but this does not seem to clear the grid.SelectedItems() collection (the count is still greater than zero). Therefore, I tried calling grid.SelectedItems.Clear(), but this yields the following exception:
+ e._exception {System.InvalidOperationException: Cannot change ObservableCollection during a CollectionChanged or PropertyChanged event.
at System.Collections.ObjectModel.ObservableCollection`1.CheckReentrancy()
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at Telerik.Windows.Data.Selection.ItemSelectionHandler.SynchronizePublicSelectedItems()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.SynchronizePublicProperties()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.SynchronizePublicPropertiesAndCleanUp()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.EndEmptySelection()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.EndSelection()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.ClearSelection()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.SelectedItems_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.ClearItems()
at System.Collections.ObjectModel.Collection`1.Clear()
--> THIS IS WHERE I CALL grid.SelectedItems.Clear
at RowReorderBehavior.OnDropInfo(Object sender, DragDropEventArgs e)
at Telerik.Windows.Controls.DragDrop.DragDropEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at Telerik.Windows.RadRoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)
at Telerik.Windows.RouteItem.InvokeHandler(RadRoutedEventArgs routedEventArgs)
at Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)
at Telerik.Windows.EventRoute.InvokeHandlers(Object source, RadRoutedEventArgs args)
at Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)
at Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.DragDropProvider_DropInfo(Object sender, DragDropEventArgs e)
at Telerik.Windows.Controls.DragDrop.DragDropProviderBase.RaiseDropInfo()
at Telerik.Windows.Controls.DragDrop.SilverlightDragDropProvider.OnDrop()
at Telerik.Windows.Controls.DragDrop.SimulatedDragDropProvider.OnCoverRectangleMouseLeftButtonUpInternal()
at Telerik.Windows.Controls.DragDrop.SilverlightDragDropProvider.OnCoverRectangleMouseLeftButtonUp(Object sender, EventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)} System.Exception {System.InvalidOperationException}
I don't see why clearing the selected items there would yield the error, since the collection is not already being modified. Any ideas?
+ e._exception {System.InvalidOperationException: Cannot change ObservableCollection during a CollectionChanged or PropertyChanged event.
at System.Collections.ObjectModel.ObservableCollection`1.CheckReentrancy()
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at Telerik.Windows.Data.Selection.ItemSelectionHandler.SynchronizePublicSelectedItems()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.SynchronizePublicProperties()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.SynchronizePublicPropertiesAndCleanUp()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.EndEmptySelection()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.EndSelection()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.ClearSelection()
at Telerik.Windows.Data.Selection.ItemSelectionHandler.SelectedItems_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.ClearItems()
at System.Collections.ObjectModel.Collection`1.Clear()
--> THIS IS WHERE I CALL grid.SelectedItems.Clear
at RowReorderBehavior.OnDropInfo(Object sender, DragDropEventArgs e)
at Telerik.Windows.Controls.DragDrop.DragDropEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
at Telerik.Windows.RadRoutedEventArgs.InvokeHandler(Delegate handler, Object target)
at Telerik.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RadRoutedEventArgs routedEventArgs)
at Telerik.Windows.RouteItem.InvokeHandler(RadRoutedEventArgs routedEventArgs)
at Telerik.Windows.EventRoute.InvokeHandlersImpl(Object source, RadRoutedEventArgs args, Boolean raisedAgain)
at Telerik.Windows.EventRoute.InvokeHandlers(Object source, RadRoutedEventArgs args)
at Telerik.Windows.RadRoutedEventHelper.RaiseEvent(DependencyObject element, RadRoutedEventArgs args)
at Telerik.Windows.DependencyObjectExtensions.RaiseEvent(DependencyObject element, RadRoutedEventArgs e)
at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.DragDropProvider_DropInfo(Object sender, DragDropEventArgs e)
at Telerik.Windows.Controls.DragDrop.DragDropProviderBase.RaiseDropInfo()
at Telerik.Windows.Controls.DragDrop.SilverlightDragDropProvider.OnDrop()
at Telerik.Windows.Controls.DragDrop.SimulatedDragDropProvider.OnCoverRectangleMouseLeftButtonUpInternal()
at Telerik.Windows.Controls.DragDrop.SilverlightDragDropProvider.OnCoverRectangleMouseLeftButtonUp(Object sender, EventArgs e)
at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)} System.Exception {System.InvalidOperationException}
I don't see why clearing the selected items there would yield the error, since the collection is not already being modified. Any ideas?