Live Chat Icon For mobile
Live Chat Icon

In my UITypeEditor for a collection, how do I change the ‘(collection)’ string to a string of my own

Platform: WinForms| Category: Type Editors

The string ‘(Collection)’ is coming from the TypeConverter on that property, which is CollectionConverter. To modify this value, do the following…

[TypeConverter(typeof(MyCollectionConverter)]
public class MyCollection : SomeBaseCollectoin
{
    // ...
}

internal class MyCollectoinConverter : System.ComponentModel.CollectionConverter 
{
      public override object ConvertTo(ITypeDescriptorContext context,
CultureInfo culture, object value, Type destinationType) 
     {
            if (destinationType == typeof(string)) 
            {
                if (value is ICollection) 
                {
                    return 'You can return what ever string value you want
here';
                }
            }
            return base.ConvertTo(context, culture, value, destinationType);
      }
}

(from sburke_online@microsoft..nospam..com on microsoft.public.dotnet.framework.windowsforms)

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.