views:

297

answers:

1

I have a DataGrid. It's ItemsSource is bound to the ModelView's CompositeCollection through the ViewModel. The CompositeCollection consists of 2 ObservableCollections.

The display on the grid is fine. I am able to see the collection. However, when I try to edit one of the rows, I get a crash (NotSupportedException) of: "'EditItem' is not allowed for this view"

How do I make the rows editable? I need to be able to edit the ModelViews representing each row in the Grid.

Here is the CompositeCollection Property code that I use to bind to the itemssource: this isn't the exact code since I am not allowed to post the exact code but it is the same logic on how I make the collection

public CompositeCollection ModelViewsCollection { get { CollectionContainer modelViewContainer;

            CompositeCollection modelViewCollection = new CompositeCollection();


            modelViewContainer= new CollectionContainer();
            modelViewContainer.Collection= this.ModelViewCollection;
            modelViewCollection .Add(modelViewContainer);

modelViewContainer= new CollectionContainer(); modelViewContainer.Collection= this.ModelViewCollection2; modelViewCollection .Add(modelViewContainer);

            return modelViewCollection;
        }
    }
A: 

CompositeCollection does not implement IEditableCollectionView which is used by the datagrid to edit.

I have had the same issues, and ended up doing my own fake composite collection on the view model, similiar to what you have, if all you are putting in your collection is two observable collections, its not to hard to track the changes listening to collection changed on both of them. and make your viewmodels collection consist of both of them

You could even do the dirty hack that i did, of rebuilding the ObservableCollection that the grid binds to every time one of the collections change (not elegant i know, but ill go back and optimise when i get time.. i.e. never) With a linq query this stuff is really easy.

Otherwise maybe you could derive from CompositeCollection and try and add the IEditableCollectionView, if you get that working be sure to let me know.

here is the same question on the datagrid forum

Aran Mulholland