更新时间:2023-01-30 14:08:20
您似乎缺少转换器:
internal class AnimalConverter : ExpandableObjectConverter {
public override object ConvertTo(ITypeDescriptorContext context,
CultureInfo culture,
object value,
Type destinationType) {
if (destinationType == typeof(string) && value is Animal) {
Animal a = (Animal)value;
return a.ToString();
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
然后装饰你的动物:
[TypeConverter(typeof(AnimalConverter))]
public class Animal {...}
发现这个代码项目 自定义显示PropertyGrid 中的集合数据很有帮助.
Found this Code Project Customized display of collection data in a PropertyGrid helpful.