Monday, June 20, 2011

HierarchicalData vs HierarchicalCollectionView as a dataprovider to the AdvancedDataGrid

So I just discovered another issue with the ADG. When you switch dataProviders from a HierarchicalCollectionView to HierarchicalData, the collection doesn't get set properly.

Here is a snippet from the set dataProvider method of the ADG.

if (value is IHierarchicalData)
            _rootModel = value as IHierarchicalData;
        else if (value is IHierarchicalCollectionView)
            // if the dataProvider is IHierarchicalCollectionView,
            // set it to super.dataProvider in commitProperties()
            _rootModel = IHierarchicalCollectionView(value).source;
            hierarchicalCollectionInstance = IHierarchicalCollectionView(value);
            _rootModel = null;
            hierarchicalCollectionInstance = null;
            super.dataProvider = value;

Notice that if you pass in a IHierarchicalCollectionView a private flag called hierarchicalCollectionInstance gets set. It gets nullified on ALL other dataprovider types EXCEPT IHierarchicalData.

This causes a IHierarchicalData following a IHierarchicalCollectionView to essentially not be saved, as the hierarchicalCollectionInstance gets referenced in commitProperties. The old IHierarchicalCollectionView will continue to be the datasource.

The easiest resolution to this is to set the dataProvider to null, then set it to the new source

No comments:

Post a Comment