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

Error when clearing selected items

1 Answer 38 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Sergey Arutchev
Top achievements
Rank 1
Sergey Arutchev asked on 07 Dec 2011, 03:58 PM
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?

1 Answer, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 09 Dec 2011, 04:17 PM
Hello Sergey Arutchev,

 I have tested the online example with clearing the SelectedItems but I was not able to get any error. Further more after the selected items are reordered, they are unselected by default.

Am I missing something? Where exactly in the code do you call the grid.UnselectAll()?

Regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
GridView
Asked by
Sergey Arutchev
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Share this question
or