Merging Collections

Grids for WPF Forum

Posted 13 years ago by Tobias Weihmann
Version: 10.2.0532
Avatar
Dear Actipro support,

What would be the recommended way to create a custom merge logic for collections? (ie. when selecting multiple objects with a collection property)

- The merge list should contain all unique items of all other collections (regardless of their position in the collection)
- Items which are not present in all lists should be flagged in order to change their appearance via a custom editor (i.e. for greying out)
- New items should be added to all collections
- Removed items should be removed from collections in which they are present
- The merged collection should be expandable and editable just as normal collections (CollectionDisplayMode set to EditableInline) or equivalent

As I see it, I would need to override TypeDescriptorDataFactory so that it returns a custom MergedPropertyDataAccessor? Will I need to create a custom version of ExpandableCollectionConverter as well? Are there any suggested readings (there does not seem to be much information on merging in the docs and Reflector displays a lot of obfuscated code)

Thank you,
Tobias

Comments (2)

Posted 13 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Tobias,

You are correct that you'd need a custom DataFactory, which would most likely derive from TypeDescriptorDataFactory. You'd need to override GetProperties(object[], DataFactoryOptions), which is responsible for merging properties. You could call the base version to merge the regular properties, then go through the objects looking for collection properties and manually merge them. To do that, you'd need to wrap them in a custom IPropertyDataAccessor that effectively wraps the collections from the various properties.

The DataFactory will be called multiple times. The first time is to get the properties of the SelectedObject(s). The subsequent calls would be to get sub-properties, which includes collection items.

You would not need a custom ExpandableCollectionConverter, as that is used by the DataFactory to get the items of the collection. These items are then wrapped in an IPropertyDataAccessor.


Actipro Software Support

Posted 13 years ago by Tobias Weihmann
Avatar
Thank you for the quick and informative reply. I will do as you described. --- Tobias
The latest build of this product (v24.1.3) was released 1 month ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.