I'm getting a strange error message on refreshing the dataContext a XamDataGrid is bound to:
Added item does not appear at given index '0
The XamDataGrid is bound to an
ObservableCollection<myObj> collection1
and this is happening only when the XamDataGrid is filtered and collection1 is cleared and new items are added.
System.InvalidOperationException was unhandled
Message="Added item does not appear at given index '0'."
Source="PresentationFramework"
StackTrace:
at System.Windows.Data.ListCollectionView.AdjustBefore(NotifyCollectionChangedAction action, Object item, Int32 index)
at System.Windows.Data.ListCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs args)
at System.Windows.Data.CollectionView.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at Infragistics.Windows.DataPresenter.ViewableRecordCollection.RaiseCollectionChanged(NotifyCollectionChangedEventArgs args)
at Infragistics.Windows.DataPresenter.ViewableRecordCollection.OnSorted_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at Infragistics.Windows.DataPresenter.RecordCollectionBase.OnCollectionChanged(NotifyCollectionChangedAction action, Object item, Int32 index)
at Infragistics.Windows.DataPresenter.RecordCollectionBase.InsertRecord(Int32 index, Record record)
at Infragistics.Windows.DataPresenter.RecordManager.InsertRecord(Int32 index, Int32 sortedIndex, DataRecord record, Boolean notifyListeners)
at Infragistics.Windows.DataPresenter.RecordManager.OnSourceCollectionAddOrRemove(NotifyCollectionChangedEventArgs e)
at Infragistics.Windows.DataPresenter.RecordManager.OnSourceCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at Infragistics.Windows.DataPresenter.RecordManager.ProcessChangeNotification(Object sender, Object eventArgs)
at Infragistics.Windows.DataPresenter.RecordManager.OnChangeNotification(Object sender, Object eventArgs, Boolean isReset)
at Infragistics.Windows.DataPresenter.RecordManager.System.Windows.IWeakEventListener.ReceiveWeakEvent(Type managerType, Object sender, EventArgs e)
at System.Windows.WeakEventManager.DeliverEventToList(Object sender, EventArgs args, ListenerList list)
at System.Windows.WeakEventManager.DeliverEvent(Object sender, EventArgs args)
at System.Collections.Specialized.CollectionChangedEventManager.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs args)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at <MyApp>.ViewModel.ViewModel.ReloadCheckList() in D:[...]ViewModel.cs:line 79
at <MyApp>.Controls.CheckListControl.CheckListNavigator_ClickedOnRefresh(Object sender, RoutedEventArgs e) in D:[...]\Controls\CheckListControl.xaml.cs:line 60
at <MyLibrary>.CustomControls.Navigator.Navigator.btnRefresh_Click(Object sender, RoutedEventArgs e) in D:[...]\Navigator\Navigator.xaml.cs:line 55
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 System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(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.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.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 <MyApp>.App.Main() in D:[...]\App.xaml.cs:line 20
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
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:
Hi
I have been facinf the same issue. Is there a resolution for this?
hi,
i forgot to write one line in my sample:
i'm doing following too after add and remove lines.
ClearRecordFilters(_deviceDataGrid);
private void ClearRecordFilters(XamDataGrid grid)
{
foreach (RecordFilter rec in grid.DefaultFieldLayout.RecordFilters)
rec.Clear();
}
Thanks
Shibu
Shibu,
I was not able to reproduce this issue in 10.3. Please, check the attached sample and let me know if you can reproduce the exception with it?
Hi,
Similar problem is faced by me too. I didn't get any solution for the same yet. What i do as follows:
private ObservableCollection<Data> _deviceGridDataSource = new ObservableCollection<Data>();
//Data is a class type.
private XamDataGrid _deviceDataGrid;
/// <summary> /// Get/Set the device data grid /// </summary> protected XamDataGrid DeviceDataGrid { get { return _deviceDataGrid; } set { _deviceDataGrid = value; _deviceDataGrid.DataSource = _deviceGridDataSource; } }
Now whenever i do following i get the exception mentioned in first post.
_deviceGridDataSource.Remove(source); // Source is of type Data
_deviceGridDataSource.Add(new Data());
Please let us know the solution for it and reason of facing such problem. Quick response will help a lot.
Hello,
I apologize that no one has yet answered this post. I was wondering if you ever found the solution to this issue? If not, how are you clearing the collection that is bound to the XamDataGrid?
Thank you!