[英]Combobox uses TypeConverter instead of toString C#
I have a class with a custom TypeDescriptor
to save and restore the data. 我有一个带有自定义TypeDescriptor
的类,用于保存和恢复数据。 In my application i use a ComboBox
to select objects of this class. 在我的应用程序中,我使用ComboBox
选择此类的对象。 To bind the objects to the ComboBox
i use the DataSource
property of the ComboBox
. 要将对象绑定到ComboBox
我使用的DataSource
中的属性ComboBox
。
After I created the custom TypeDescriptor
for my class, the ComboBox
uses the TypeDescriptor
to display the Text
instead of the ToString
method of my class. 在为类创建自定义TypeDescriptor
之后, ComboBox
使用TypeDescriptor
显示Text
而不是类的ToString
方法。
How can I change the ComboBox
to use the ToString
method instead of the TypeDescriptor
? 如何更改ComboBox
以使用ToString
方法代替TypeDescriptor
?
By using a wrapper class and populate the ComboBox
with that? 通过使用包装器类并在其中填充ComboBox
?
private class ComboItem
{
private MyClass theWrappedInstance;
internal ComboItem(MyClass c)
{
theWrappedInstance = c;
}
public override ToString()
{
return theWrappedInstance.ToString();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.