Mult-Select and Collection Properties (merged properties)

Grids for WPF Forum

Posted 6 years ago by Wiley Knoch
Version: 16.1.0635
Avatar

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

Comments (8)

Answer - Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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 6 years ago by Wiley Knoch
Avatar

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 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

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

Posted 6 years ago by Wiley Knoch
Avatar

I cannot seem to get a zipped solution replicating this issue emailed to you.  But here is the example, create a Window and add a property grid to it named "Name = propgrid".  Then in the Window code behind add this:

using ActiproSoftware.Windows.Controls.Editors.Interop.PropertyGrid.PropertyEditors;
using ActiproSoftware.Windows.Controls.PropertyGrid.Editors;

namespace EnumMergeTest
{
   /// <summary>
   /// Interaction logic for MainWindow.xaml
   /// </summary>
   public partial class MainWindow : Window
   {
      public MainWindow()
      {
         InitializeComponent();

         propgrid.SelectedObjects = new[]
         {
            new EnumTest() { Enum = Test.One },
            new EnumTest() { Enum = Test.Two },
            new EnumTest() { Enum = Test.Three }
         };
      }

      public enum Test
      {
         One,
         Two,
         Three,
      }

      public class EnumTest
      {
         [System.ComponentModel.Editor(typeof(EnumPropertyEditor), typeof(PropertyEditor))]
         public Test Enum { get; set; }
      }
   }
}

You will see the dropdown in the grid will show nothing.  I would hope it would show the options but nothing is selected because the value is different for each of the objects.

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Wiley,

I am trying the above code with both the newer PropertyGrid control with updated codebase in the Grids assembly and also the legacy PropertyGrid that ships in v2018.1 (same general codebase as your v2016.1), and I'm not seeing a blank dropdown.  Maybe try the latest version (we recommend the newer Grids assembly's PropertyGrid implementation since it's better and faster) and see if you still see it there?


Actipro Software Support

Posted 6 years ago by Wiley Knoch
Avatar

Unfortunately I cannot upgrade the version to the new PropertyGrid because of time constraints and too many custom behaviors that are broken by the newer version.  Is there any way I could get source just for version 16's EnumPropertyEditor, EnumEditBox, and EnumListBox so I can code the fix on my end?

Posted 6 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Wiley,

Like I mentioned above, there is a legacy version of PropertyGrid that can be installed by the 2018.1 installer and has virtually the same codebase as the 2016.1 version.  That's what I wanted you to try and see if you still had the problem with that, since I couldn't repro it with that either.  You can take a look at the Grids' "Converting to 2017.1" topic in the documentation for more info on using the legacy PropertyGrid assemblies.  The last section in that topic covers it.


Actipro Software Support

Posted 6 years ago by Wiley Knoch
Avatar

Upgraded to 2018.1 and used the legacy assemblies for the property grid but the EnumPropertyEditor still has the bug in it where it will not display the enum options in the dropdown when the selected objects values differ, the dropdown is blank.

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.