简体   繁体   English

Combobox使用TypeConverter而不是toString C#

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM