I have a custom object type which has to be editable in PropertyGrid:
public class CustomObjectType
{
public string Name { get; set; }
public List<CustomProperty> Properties {get; set;}
}
Which has a list of custom properties:
public class CustomProperty
{
public string Name { get; set; }
public string Desc { get; set; }
public Object DefaultValue { get; set; }
Type type;
public Type Type
{
get
{
return type;
}
set
{
type = value;
DefaultValue = Activator.CreateInstance(value);
}
}
}
The main problem here is that the PropertyGrid control doesn’t allow to edit, nor uses appropriate editing tools for property DefaultValue which is beforehand instantiated by setting value of CustomProperty‘s field Type.
Type of DefaultValue is only known at runtime.
Moreover I need to supply a custom TypeConverter for CustomProperty‘s property Type to show a drop-down list of supported types (for example, Int, String, Color, MyOwnClass).
How would i do that?
To go down this route, you would need to create a custom
PropertyDescriptorper property. You would then expose that via a customTypeConverter, or (alternatively)ICustomTypeDescriptor/TypeDescriptionProvider. Example: