w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Datagrid inside datagrid - With filter based on parent datagrid value

You're right, its difficult to apply a filter to a list of items in xaml, much easier to have a view model where each parent object has an ObservableCollection or CollectionView of child objects. You will need a AllShipmentsVM, ShipmentVM, ContainerVM and possibly a PackageVM.

If the data coming from a database, could you use EF to build your collection of child objects?

Otherwise, use a ICollectionView to display the items and set the filter for each parent viewmodel...

        foreach (var s in allShipments)
        {
            var svm = new ShipmentVM
            {
                Shipment = s,
                Containers = (new CollectionViewSource { Source =
allContainerVMs }).View
            };
            svm.Containers.Filter = (o) => (o as
ContainerVM).Container.ShipmentID == svm.Shipment.ShipmentID;
            allShipmentVMs.Add(svm);
        }




© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.