Nested datagrid inside dataform with MVVM, what is the correct approch ?

Jun 7, 2012 at 4:12 PM

Hello !

Here's my problem. I'am using Simple MVVM with RIA services and I want to enable editing child entities of an entity through a datagrid on a dataform.

Based on Microsoft Northwind database, we have a "Region" that can have multiple "Territories". I have a View with my region list and a dataform to a edit one Region (both synchronized). When I am editing a region, I want to display on the dataform the territories list (on a datagrid) and I want to be able to edit this list directly on the datagrid. 

I'am not sure how to do that correctly, does I have to recreate on ViewModels my hierachical structure of Models ?

So, for my RegionsView I will have a RegionsViewModel. This RegionsViewModels should have an ObservableCollection of "Region" (entities of my model) or of RegionDetailViewModel ? 

If I choose an ObservableCollection of "Region", my dataform fields will be bind directly to the model and particulary the datagrid representing the territories list... In that case, am I breaking the MVVM approch, no ? If not, how can I add some custom logics for validation, or anything else during the territories edition ?

If I choose an ObservableCollection of "RegionDetailViewModel", I will have to recreate and maintains my hierarchical objets structure and synchronize my view models... Maybe it will became very complicated things...

What is the best approch ? Thanks for any help.