I confront with the following situation:
I have WPF Datagrid bound to a CollectionViewSource.
This CollectionViewSource has GroupDescriptions and the source collection is an ObservableCollection.
At some point I do this:
IEditableCollectionView iecv = CollectionViewSource.GetDefaultView((thisas DataGrid).ItemsSource) as IEditableCollectionView;
and manually add one item like this:
object newItem = iecv.AddNew(); iecv.CommitNew();
Here a I get the following exception:
"Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"
if the iecv has only NewItemPlaceholder as item.
If I remove the GroupDescriptions from CollectionViewSource it works without any problem.
Also, if I have at least one item (besides NewItemPlaceholder) in the collection, works fine.
What I noticed is that in this case, after AddNew runs, the ListCollectionView’s Count remains the same (meaning 1), although it should be incremented by 1, that’s why the exception raises.
So, what is happening? Is this a bug?
Thanks in advance!