Question

Mult-Select and Collection Properties (merged properties)

Posted 7 days ago by Avatar Wiley Knoch

I have custom collection class and a custom TypeConverter that inherits ExpandableCollectionConverter:

   /// <summary>
   /// A collection of display object for property grids
   /// </summary>
   [TypeConverter(typeof(DisplayCollectionConverter))]
   public class DisplayCollection<T> : Collection<T>

   /// <summary>
   /// Converter class for DisplayCollection
   /// </summary>
   public class DisplayCollectionConverter : ExpandableCollectionConverter  

I use this for all types of collection based properties that I show in the grid and it works great when PropertyGrid.SelectedObjects = object[1] but as soon as I have multiple objects selected (all of the same concrete type) any properties that use this DisplayCollection will not allow me to add/create new items, the + disappears for them.

What do I need to do to get the grid to allow me to still Add items to these collection properties?  I understand this can get complicated if the collections differ between the selected items, but in a very simple case of the collections being empty how can I get the Add (+) enabled to add items for multiple objects?  Of course the next question will be how to handle differing collections (merging)?

Thank you for any help

Information The latest build of this product (2018.1 build 0671) was released 10 days ago, which was before this thread was created.

Comments (3)

Posted 5 days ago by Actipro Software Support - Cleveland, OH, USA

Hi Wiley,

That is correct, a merged property doesn't support merging of collections. 

If you want to force it to be allowed, you could inherit the TypeDescriptorFactory class and override the CreateMergedPropertyModel method.  That returns a MergedPropertyModel instance by default.  You could make a class that inherits MergedPropertyModel and overrides CanAddChildCore and AddChild.  Those are what control the add button, so add appropriate logic to them.

If you override the ConverterCore property to return an ExpandableCollectionConverter instance, you can support expansion.


Actipro Software Support
Posted 5 days ago by Wiley Knoch

Thank you I think I can run with that to get the collection based properties working.  1 more issue I am having is with enum properties and using the built in EnumPropertyEditor.  When I have merged properties that have their enum set to the same value the editor dropdown properly displays and shows the selected value and I can change it to something else which is applied to all selected objects, great!  But when the enums differ the field in the grid is set to No Value and the dropdown is blank.

Is there a way to make this work where the dropdown will display with none of the fields selected to allow me to pick a value to apply to the selected objects?

Posted 4 days ago by Actipro Software Support - Cleveland, OH, USA

Hi Wiley,

I tried to repro this but was unable to.  Can you please make a new simple sample project that shows this scenario and email it to our support address?  Reference this thread in your email and be sure to exclude any bin/obj files from the ZIP you send, along with renaming the .zip file extension so it doesn't get spam blocked.  Thanks!


Actipro Software Support

Add a Comment

Please log in to a validated account to post comments.