multiple datagrids showing treeview selection and children

Oct 5, 2009 at 3:53 AM


I have been trying to create an MVVM for 3 data grids that show related content as in tree related tables in a typed dataset. In code I had it working as simple as this

            BuyClientCustomDset.ClientRow buyClientRow = (BuyClientCustomDset.ClientRow)((TreeViewItem)e.OriginalSource).Tag;
            // Master
            System.Data.DataView gridDataView = new System.Data.DataView(this.viewModel.buyDset.ContributionPhone);
            gridDataView.RowFilter = "ClientId=" + buyClientRow.ClientId;
            this.myMasterDataGrid.ItemsSource = gridDataView;
            this.myMasterDataGrid.ToolTip = "Contribution Phones for client: " + buyClientRow.ClientName;
            // Detail
            Binding b = new Binding();
            b.Source = gridDataView;
            b.Path = new PropertyPath("FK_CreativeReel_ContributionPhone");
            this.myDetailDataGrid.SetBinding(DataGrid.ItemsSourceProperty, b);
            this.myDetailDataGrid.ToolTip = "Creative Reels with contribution client contribution phone selected above";
            // Detail detail
            Binding c = new Binding();
            c.Source = gridDataView;
            c.Path = new PropertyPath("FK_CreativeReel_ContributionPhone/FK_CreativeReelDelivery_CreativeReel");
            this.myDetailDetailDataGrid.SetBinding(DataGrid.ItemsSourceProperty, c);
            this.myDetailDetailDataGrid.ToolTip = "Creative Reels Deliveries for creative selected above";

This works like a charm.

But I want to utilize a model-view-view model where the Property path (shown above) is not hardcoded but instead it is dynamically set according to the relationship of the following tables in the hierarchy, tables contained in a typed dataset that has many many tables. I would like to bind the related tables to three datagrid controls declared in the xaml file in such a way that:  when I select another dataset path in the Tree-view control (also declared in the xaml file and also bound to the same typed dataset), the three data-grid controls in the right hand side of window will get properly populated with the selection and its children tables. Also when you select any row in any of the data-grid controls the children data-grid controls will be populated according to the relationship of the selection. It Seems easy in the code above but with the MVVM pattern I have tried many different ways without success, any help on how to set this up will be greatly appreciated.

I have look into simpler examples with hardcoded binding paths, master-detail data-grids, etc. and they all work, it is only when I reach this level of complexity:  multiple related tables (more than 5) in a typed dataset, a tree-view with more than three levels, and more than two data-grids in a “Master, detail, and detail-detail” fashion.  So it will be greatly appreciated if in your answer, or link reference you address this level of complexity.

Thank you in advance