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

Calling Rebind() from RowEditEnded event handler throws Exception

3 Answers 67 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Gary
Top achievements
Rank 1
Gary asked on 15 Aug 2013, 11:11 AM
We have a requirement to display, along with other columns, a cumulative value column within the RadGridView.  To do this we attach a behavior to the RadGridView.  The relevant code from the behavior is this:

protected override void OnAttached()
       {
           AssociatedObject.DataLoaded += AssociatedObject_DataLoaded;
           AssociatedObject.RowEditEnded += AssociatedObject_RowEditEnded;
           base.OnAttached();
       }
 
       void AssociatedObject_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
       {
           // This is the call to Rebind that causes the exception
           AssociatedObject.Rebind();
       }
 
       protected override void OnDetaching()
       {
           AssociatedObject.DataLoaded -= AssociatedObject_DataLoaded;
           AssociatedObject.RowEditEnded -= AssociatedObject_RowEditEnded;
           base.OnDetaching();
       }
 
       void AssociatedObject_DataLoaded(object sender, EventArgs e)
       {
           UpdateTotalLengths();
           UpdateComponentNumber();
       }
 
       private void UpdateComponentNumber()
       {
           Int32 index = 1;
           foreach (MyComponent component in AssociatedObject.Items.OfType<MyComponent>())
           {
               component.Number = index;
               index++;
           }
       }
 
       private void UpdateTotalLengths()
       {
           var totalLength = 0d;
           foreach (var component in AssociatedObject.Items.OfType<MyComponent>())
           {
               totalLength += component.Length;
               component.TotalLength = totalLength;
           }
       }

The basic idea of the above code is that on RowEndEdit and on DataLoaded the cumulativelength value is recalculated.

Everything works as expected when the user selects another row after editing a row (i.e. the cumulative length is updated).  However when the user clicks on anywhere else in the UI an ArgumentNullException is thrown (the message is 'Value cannot be null').  The Stack trace is:

at Telerik.Windows.Controls.ParentOfTypeExtensions.<GetParents>d__0.MoveNext() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\Extensions\ParentOfTypeExtensions.cs:line 74
at System.Linq.Enumerable.<OfTypeIterator>d__aa`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Telerik.Windows.Controls.GridView.GridViewCell.HandlePendingEdit(UIElement focusedElement) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Cells\GridViewCell.cs:line 1021
at Telerik.Windows.Controls.GridView.GridViewCell.HandlePendingEditOnLostFocus() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Cells\GridViewCell.cs:line 899
at Telerik.Windows.Controls.GridView.GridViewDataControl.HandleLostFocus(DependencyObject focusedDependencyObject) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Editing.cs:line 508
at Telerik.Windows.Controls.GridView.GridViewDataControl.HandleLostFocus() in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Editing.cs:line 456
at Telerik.Windows.Controls.GridView.GridViewDataControl.OnLostFocus(RoutedEventArgs e) in c:\TB\102\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\GridViewDataControl.Editing.cs:line 450
at System.Windows.UIElement.IsFocused_Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.ClearValueCommon(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata)
at System.Windows.DependencyObject.ClearValue(DependencyPropertyKey key)
at System.Windows.Input.FocusManager.OnFocusedElementChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
at System.Windows.Input.FocusManager.SetFocusedElement(DependencyObject element, IInputElement value)
at System.Windows.Input.KeyboardNavigation.UpdateFocusedElement(DependencyObject focusTarget)
at System.Windows.FrameworkElement.OnGotKeyboardFocus(Object sender, KeyboardFocusChangedEventArgs e)
at System.Windows.Input.KeyboardFocusChangedEventArgs.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.RaiseTrustedEvent(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.KeyboardDevice.ChangeFocus(DependencyObject focus, Int32 timestamp)
at System.Windows.Input.KeyboardDevice.TryChangeFocus(DependencyObject newFocus, IKeyboardInputProvider keyboardInputProvider, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
at System.Windows.Input.KeyboardDevice.Focus(DependencyObject focus, Boolean askOld, Boolean askNew, Boolean forceToNullIfFailed)
at System.Windows.Input.KeyboardDevice.Focus(IInputElement element)
at System.Windows.UIElement.Focus()
at System.Windows.Controls.ScrollViewer.OnMouseLeftButtonDown(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonDownThunk(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.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent)
at System.Windows.UIElement.OnMouseDownThunk(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.RaiseTrustedEvent(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, WindowMessage 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, Int32 numArgs)
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)

I have tracked this down to the call to Rebind() on the RowEditEnded.

Note we are trying to use Rebind here instead of just raising PropertyChanged event from component.TotalLength as we are not in control of that library.

3 Answers, 1 is accepted

Sort by
0
Nedyalko Nikolov
Telerik team
answered on 20 Aug 2013, 07:38 AM
Hi,

I've tried to reproduce the exception unfortunately to no avail. I'm attaching my sample project - could you use it for a reference and provide me with a little bit more information how to simulate the exception.

I've investigated your code and I think that what you are trying to achieve is a SUM aggregate function. You may take a look at this online example for more information how to use aggregate functions.

Regards,
Nedyalko Nikolov
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Gary
Top achievements
Rank 1
answered on 20 Aug 2013, 10:43 AM
Hi Nedyalko,

My colleague has submitted a support ticket for this (ticket #728248) so that we can attach a project to repo this behaviour, feel free to continue this through the support ticket or here.

Regards,
Gary
0
Yoan
Telerik team
answered on 23 Aug 2013, 11:03 AM
Hi Gary,

We have already answered you in the other thread you have posted on the same subject. Also I am posting the answer here in case if someone else has the same problem:

We've fixed a similar issue lately, so just get the latest version (2013.2.0724.40) and let me know how it works on your end. I've just tested your project with assemblies from 2013.Q2.SP1 (2013.2.0724.40) and everything works as expected.


Regards,
Yoan
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
GridView
Asked by
Gary
Top achievements
Rank 1
Answers by
Nedyalko Nikolov
Telerik team
Gary
Top achievements
Rank 1
Yoan
Telerik team
Share this question
or