Default impl does not allow adding strings to collections

Grids for WPF Forum

Posted 12 years ago by Wes Cumberland - Barclays Capital
Version: 10.2.0532

I've found that collection properties of type ICollection<string> (with the actual type being a List<string>) do not show the (+) button. If I override the ExpandableCollectionConverter and always return true for CanAddChild() then the button shows up as expected and it actually works, I'm able to add strings to the collection.

Also, related (but perhaps out of scope for this question), It seems that dictionary types are not able to be added to? the (+) button never shows up and when I force it to show up with the override mentioned above, clicking it does not work.

I'm submitting this as a question because I'm new to using the propertygrid and I'm on a slightly older version. So perhaps this is normal behaviour, but I was surprised to see the add-to-string-collection work after I forced the button to show.

Will adding to string collections and/or dictionaries be added in the future or are they supported now in the 11.1 releases?

Thank you!

Comments (1)

Posted 12 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Wes,

We've updated the default behavior to add empty strings in the upcoming release. The original behavior would only allow adding if the item type was a value type or had a default constructor, neither of which fits the string type.

As you said, you can force it to allow nulls, but again the default behavior is to not allow null values. In the current version, you could also override the CreateItem and return string.Empty to add empty strings, instead of nulls.

Dictionaries are a bit different, as you need to specify both a "key" and a "value". As we have no idea what type of key to add and don't want to add duplciates, the default behavior is to not add anything. You can create a class that derives from ExpandableCollectionConverter and override the CanAddItem, AddItem, CreateItem methods to allow adding to your custom dictionaries.

Actipro Software Support

The latest build of this product (v24.1.2) 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.