Question

property editor for list of strings

Posted 4 years ago by Avatar Mary Fontana - Rudolph Technologies
I have a class that has a list of values.

[TypeConverter(typeof(ExpandableObjectConverter))]
public MyClass
{
public string Name {get set; }

[TypeConverter(typeof(StringCollectionConverter))]
public List<string> Values {get;}

}


If I use the default prop editor, there is not a + for adding a string value.
I extended ExpandableObjectConverter with StringCollectionConverter to show in the Values field instead of "2 items" the names of the items such as "AA, BB"
But if I change the value of one of the items, the string "AA, BB" does not get modified.

Is there a prop editor for list of strings/numbers?


Any suggestions?

Comments (1)

Posted 4 years ago by Actipro Software Support - Cleveland, OH, USA
Hi Mary,

The PropertyGrid needs to be notified that your Values property changed. You can notify it several ways:

1. Change Values to be an ObservableCollection and attach to the CollectionChanged event in MyClass. Then you'd need to implement INotifyPropertyChanged on MyClass and raise the PropertyChanged event for the Values property when it's collection is changed.

2. For the IPropertyDataAccessor to be refreshed from your custom ExpandableCollectionConverter when an item is added. Something like:
public class MyExpandableCollectionConverter : ExpandableCollectionConverter, ICollectionTypeConverter {
    bool ICollectionTypeConverter.AddItem(IPropertyDataAccessor propertyDataAccessor, object item) {
        if (propertyDataAccessor != null && this.AddItem(propertyDataAccessor, item)) {
            propertyDataAccessor.Refresh();
            return true;
        }
        return false;
    }
}
Note: We've made the ExpandableCollectionConverter.AddItem method virtual for the next release, so you don't have to explicitly define the ICollectionTypeConverter method like above.

3. A custom DataFactory and property data accessors could also be used.

We can give you more information on #3 if you want, but your best bet would probably be option #1 or #2.

Actipro Software Support
Information The latest build of this product (2014.2 build 0610) was released 2 months ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.