想实现的功能:
能为一个自定义控件的一个属性(类型为自定义类型集合List<MyStrcut>)提供设计时的编辑.
下面是我的代码,设计时能弹出集合编辑对话框,但是点击添加按钮时候,就抱未找到XX类型上的构造函数.
哪位高手指点下啊.
public class ListBoxExItem
{
public string text;
public int color;
public ListBoxExItem(string text, int color)
{
this.text = text;
this.color = color;
}
}
public class ListBoxExItemConverter : ExpandableObjectConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
if (sourceType == typeof(string))
{
return true;
}
return base.CanConvertFrom(context, sourceType);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(InstanceDescriptor))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
{
string obj = (string)value;
string[] parameters = obj.Split(',');
ListBoxExItem item = new ListBoxExItem(
parameters[0],
int.Parse(parameters[1]));
return item;