GridView crashes when deselecting a row using IEnumerable

4 posts, 0 answers
  1. Alanm
    Alanm avatar
    18 posts
    Member since:
    Mar 2007

    Posted 27 May 2011 Link to this post

    GridView in WPF Q1 2011 throws a Null Pointer Exception when trying to deselect a previously selected row.

    I've tried:

    DocumentGrid.UnselectAll()

    DocumentGrid.SelectedItems.Clear()

    DocumentGrid.SelectedItem = Nothing

    All trigger the exception as does Grouping when a row is selected.

    The problem only occurs when using an IEnumerable as an ItemsSource.  Changing this to mysource.ToList() fixes the problem.

    System.Reflection.TargetInvocationException was unhandled 
      Message=Exception has been thrown by the target of an invocation. 
      Source=mscorlib 
      StackTrace: 
           at System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) 
           at System.RuntimeMethodHandle.InvokeMethodFast(Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) 
           at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) 
           at System.Delegate.DynamicInvokeImpl(Object[] args) 
           at System.Windows.RoutedEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) 
           at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
           at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
           at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
           at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) 
           at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) 
           at Telerik.Windows.Controls.DataControl.RaiseSelectionChangedEvent(SelectionChangeEventArgs args) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\DataControl.Selection.cs:line 391 
           at Telerik.Windows.Controls.GridView.GridViewDataControl.RaiseSelectionChangedEvent(SelectionChangeEventArgs args) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Selection.cs:line 347 
           at Telerik.Windows.Controls.DataControl.RaiseSelectionChangedEvent(ItemSelectionChange selectionChange) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\DataControl.Selection.cs:line 381 
           at Telerik.Windows.Controls.DataControl.Telerik.Windows.Data.Selection.ISelectorInternal.RaiseSelectionChangedEvent(ItemSelectionChange selectionChange) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\DataControl.Selection.cs:line 528 
           at Telerik.Windows.Data.Selection.ItemSelectionHandler.RaiseSelectionChanged(ItemSelectionChange selectionChange) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Selection\ItemSelectionHandler.cs:line 928 
           at Telerik.Windows.Data.Selection.ItemSelectionHandler.RaiseSelectionChangedAndSyncCurrentWithSelectedIfNeeded(ItemSelectionChange selectionChange) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Selection\ItemSelectionHandler.cs:line 712 
           at Telerik.Windows.Data.Selection.ItemSelectionHandler.EndAllowedSelection(ItemSelectionChange selectionChange) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Selection\ItemSelectionHandler.cs:line 649 
           at Telerik.Windows.Data.Selection.ItemSelectionHandler.EndPendingSelection(ItemSelectionChange pendingSelection) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Selection\ItemSelectionHandler.cs:line 619 
           at Telerik.Windows.Data.Selection.ItemSelectionHandler.EndSelection() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Selection\ItemSelectionHandler.cs:line 600 
           at Telerik.Windows.Data.Selection.ItemSelectionHandler.DeselectAllNonExistentItems() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Selection\ItemSelectionHandler.cs:line 318 
           at Telerik.Windows.Data.Selection.ItemSelectionHandler.HandleItemsReset() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Selection\ItemSelectionHandler.cs:line 295 
           at Telerik.Windows.Data.Selection.ItemSelectionHandler.HandleItemsChanged(NotifyCollectionChangedEventArgs itemsChangedArguments) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Selection\ItemSelectionHandler.cs:line 187 
           at Telerik.Windows.Controls.GridView.Selection.CompositeSelectionHandler.Items_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\Selection\CompositeSelectionHandler.cs:line 63 
           at System.Collections.Specialized.NotifyCollectionChangedEventHandler.Invoke(Object sender, NotifyCollectionChangedEventArgs e) 
           at Telerik.Windows.Data.DataItemCollection.OnCollectionChanged(NotifyCollectionChangedEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\DataItemCollection.cs:line 665 
           at Telerik.Windows.Data.DataItemCollection.OnCollectionViewCollectionChanged(NotifyCollectionChangedEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\DataItemCollection.cs:line 642 
           at Telerik.Windows.Data.DataItemCollection.Telerik.Windows.Data.IWeakEventListener<System.Collections.Specialized.NotifyCollectionChangedEventArgs>.ReceiveWeakEvent(Object sender, NotifyCollectionChangedEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\DataItemCollection.cs:line 1046 
           at Telerik.Windows.Data.WeakEvent.WeakListener`1.Handler(Object sender, TArgs args) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\WeakEvents\WeakEvent.cs:line 33 
           at Telerik.Windows.Data.QueryableCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 679 
           at Telerik.Windows.Data.QueryableCollectionView.RefreshOverride() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 824 
           at Telerik.Windows.Data.QueryableCollectionView.RefreshInternal() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 771 
           at Telerik.Windows.Data.QueryableCollectionView.RefreshOrDefer() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 765 
           at Telerik.Windows.Data.QueryableCollectionView.ProcessSynchronousCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 1044 
           at Telerik.Windows.Data.QueryableCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 985 
           at Telerik.Windows.Data.QueryableCollectionView.OnRefresh() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 294 
           at Telerik.Windows.Data.QueryableCollectionView.Refresh() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.cs:line 288 
           at Telerik.Windows.Data.QueryableCollectionView.EndDefer() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.Defer.cs:line 60 
           at Telerik.Windows.Data.QueryableCollectionView.DeferHelper.Dispose() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\QueryableCollectionView.Defer.cs:line 95 
           at Telerik.Windows.Data.DataItemCollection.EndDefer() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\DataItemCollection.ICollectionView.cs:line 208 
           at Telerik.Windows.Data.DataItemCollection.DeferHelper.Dispose() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Data\Collections\DataItemCollection.ICollectionView.cs:line 231 
           at Telerik.Windows.Controls.GridView.GridViewDataControl.PerformGrouping(IGroupDescriptor descriptor, Nullable`1 insertionIndex, GroupingEventAction action) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Grouping.cs:line 182 
           at Telerik.Windows.Controls.GridView.GridViewDataControl.<>c__DisplayClass36.<RequestGrouping>b__35() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Grouping.cs:line 137 
           at Telerik.Windows.Controls.CursorManager.PerformTimeConsumingOperation(FrameworkElement frameworkElement, Action action) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\CursorManager.cs:line 16 
           at Telerik.Windows.Controls.GridView.GridViewDataControl.RequestGrouping(IGroupDescriptor descriptor, Nullable`1 insertionIndex, GroupingEventAction action) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Grouping.cs:line 127 
           at Telerik.Windows.Controls.GridView.DragDropController.OnGroupPanelDropInfo(Object sender, DragDropEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\DragDrop\DragDropController.GroupPanel.cs:line 97 
           at Telerik.Windows.Controls.DragDrop.DragDropEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDrop\DragDropEventArgs.cs:line 45 
           at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
           at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
           at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
           at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) 
           at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) 
           at Telerik.Windows.Controls.DragDrop.RadDragAndDropManager.DragDropProvider_DropInfo(Object sender, DragDropEventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDrop\RadDragAndDropManager.cs:line 319 
           at Telerik.Windows.Controls.DragDrop.DragDropProviderBase.RaiseDropInfo() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDrop\DragProviders\DragDropProviderBase.cs:line 170 
           at Telerik.Windows.Controls.DragDrop.SimulatedDragDropProvider.OnDrop() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDrop\DragProviders\SimulatedDragDropProvider.cs:line 342 
           at Telerik.Windows.Controls.DragDrop.SimulatedDragDropProvider.OnCoverRectangleMouseLeftButtonUpInternal() in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDrop\DragProviders\SimulatedDragDropProvider.cs:line 241 
           at Telerik.Windows.Controls.DragDrop.WPFSimulatedDragDropProvider.OnCoverRectangleMouseLeftButtonUp(Object sender, EventArgs e) in c:\Builds\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDrop\DragProviders\WPFSimulatedDragDropProvider.cs:line 391 
           at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) 
           at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
           at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
           at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
           at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) 
           at System.Windows.UIElement.CrackMouseButtonEventAndReRaiseEvent(DependencyObject sender, MouseButtonEventArgs e) 
           at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e) 
           at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) 
           at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
           at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
           at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
           at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) 
           at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) 
           at System.Windows.Input.InputManager.ProcessStagingArea() 
           at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) 
           at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) 
           at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) 
           at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
           at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
           at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
           at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 
           at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Boolean isSingleParameter) 
           at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) 
           at System.Windows.Threading.Dispatcher.WrappedInvoke(Delegate callback, Object args, Boolean isSingleParameter, Delegate catchHandler) 
           at System.Windows.Threading.Dispatcher.InvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Boolean isSingleParameter) 
           at System.Windows.Threading.Dispatcher.Invoke(DispatcherPriority priority, Delegate method, Object arg) 
           at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam) 
           at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg) 
           at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame) 
           at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame) 
           at System.Windows.Threading.Dispatcher.Run() 
           at System.Windows.Application.RunDispatcher(Object ignore) 
           at System.Windows.Application.RunInternal(Window window) 
           at System.Windows.Application.Run(Window window) 
           at System.Windows.Application.Run() 
           at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) 
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args) 
           at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel) 
           at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly() 
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData) 
           at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext) 
           at System.Activator.CreateInstance(ActivationContext activationContext) 
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone() 
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 
           at System.Threading.ThreadHelper.ThreadStart() 
      InnerException: System.NullReferenceException 
           Message=Object reference not set to an instance of an object.

     

  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 28 May 2011 Link to this post

    Hello Alanm,

    Is there any particular reason why .ToList() should not be used? Using a plain Enumerable can cause many problems depending you the way the enumerable is constructed. 


    Regards,
    Milan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Alanm
    Alanm avatar
    18 posts
    Member since:
    Mar 2007

    Posted 31 May 2011 Link to this post

    Hi, Thanks for the response.

    I don't have a problem using .ToList() in this case.  It is probably the correct thing to do aswell since as you say I don't know how RadView is going to handle it and IEnumerable can cause issues under certain looping conditions.  It don't think it should hard crash with an obscure error message though.  It took me quite a while to work out what the problem was, it's certainly not obvious.  Perhaps a warning if you pass a plain IEnumerable would be helpful so it easier to debug?
  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 01 Jun 2011 Link to this post

    Hello Alanm,

    Thank for the suggestions. Most probably we will add some information about this in our documentation. 



    Best wishes,
    Milan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top