Symptom
When using an EditableRootListBase (ERLB) with the .net 3.5 SP1 IEditableCollectionView, calling SaveItem() to save an item in the collection causes the item in the collection to be replaced with the result of the save, however System.Windows.Data.BindingListCollectionView keeps a cached reference to the item before the save operation. Subsequent uses of the IEditableCollectionView then point to the incorrect object.
Description:
The call to SaveItem on the ERLB causes a BindingList<>.ListChanged even to be raised with the ItemChanged flag. The IEditableCollectionCiew handles this event with the following code (from reflector since they STILL don't have 3.5 SP1 up on source servers) from private void OnListChanged:
case ListChangedType.ItemChanged:
if (!this._itemsRaisePropertyChanged.HasValue)
{
changedItem = this.InternalList[args.NewIndex];
this._itemsRaisePropertyChanged = new bool?(changedItem is INotifyPropertyChanged);
}
if (this._itemsRaisePropertyChanged.Value)
{
goto Label_032D;
}
goto Label_02E9;
default:
goto Label_032D;
}
args2 = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, changedItem, newIndex + num);
goto Label_032D;
Label_02E9:
if (this.IsEditingItem)
{
this.ImplicitlyCancelEdit();
}
if (this.IsAddingNew)
{
this._newItemIndex = this.InternalList.IndexOf(this._newItem);
if (this._newItemIndex < 0)
{
this.EndAddNew(true);
}
}
base.RefreshOrDefer();
Label_032D:
if (args2 != null)
{
base.OnCollectionChanged(sender, args2);
}
Other flags actually cause the internal cache to be updated, such as ItemMoved:
this._cachedList.RemoveAt(args.OldIndex);
this._cachedList.Insert(args.NewIndex, changedItem);
Ergo, the cache is NOT updated when the SaveItem is called on the ERLB, and references to CurrentItem, etc. are pointing to the incorrect item.
Let me know if there is something I am missing, or how to work around this. Thanks in advance!
Hi,
this sounds like the issue I am having with the new DataGrid. I think it uses a IEditableCollectionView in the background. I also seem to get the same object back from the cache when updating a cell a 2nd time. Just saw this post after firing off a question on the DataGrid and ERLB.
Volker
Please see the post in this thread for a possible partial fix for the issue.
Copyright (c) Marimer LLC