简体   繁体   English

将属性更改为propertygrid中的组合框

[英]change property to combobox in propertygrid

I have this code from internet source, I thought this code might be working well for changing the property from textbox to combobox in PropertyGrid, but after I run this, it is still a textbox. 我有来自互联网源代码的这段代码,我认为这段代码可能适用于将属性从文本框更改为PropertyGrid中的组合框,但在运行之后,它仍然是一个文本框。 Could anyone help to solve this? 有人可以帮忙解决这个问题吗?

 public class Testing
{   

    private String _formatString;
    [Category("Display")]
    [DisplayName("Format String")]
    [Description("Format string governing display of data values.")]
    [DefaultValue("")]
    [TypeConverter(typeof(FormatStringConverter))]
    public String FormatString { get; set; }

    public class FormatStringConverter : StringConverter
    {
        List<String> list = new List<String>();

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } // true means show combobox
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } // true list to list, false will show the list, but allow free=form.
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {

            list.Add("Curren");
            list.Add("Currency");
            list.Add("Scientific Notation");
            list.Add("General Number");
            list.Add("Number");
            list.Add("Percent");
            list.Add("Time");
            list.Add("Date");



            return new StandardValuesCollection(list);
        }
    }
}

If we need to display property value from TextBox to ComboBox, we want to write custom editor for specific property type. 如果我们需要从TextBox到ComboBox显示属性值,我们想要为特定的属性类型编写自定义编辑器。 Please find the below code snippet to display property value (which is type of String array) in ComboBox 请在ComboBox中找到以下代码片段以显示属性值(String数组的类型)

     public class ComboBoxEditor : ITypeEditor
    {
        public void Attach(PropertyViewItem property, PropertyItem info)
        {

        }

        ComboBoxAdv cmb;
        public object Create(PropertyInfo propertyInfo)
        {
            cmb = new ComboBoxAdv();
            cmb.Items.Add("Curren");
            cmb.Items.Add("Currency");
            cmb.Items.Add("Scientific Notation");
            cmb.Items.Add("General Number");
            cmb.Items.Add("Number");
            cmb.Items.Add("Percent");
            cmb.Items.Add("Time");
            cmb.Items.Add("Date");
            return cmb;
        }

        public void Detach(PropertyViewItem property)
        {
            throw new NotImplementedException();
        }

}

CustomEditor ComboBoxEditor = new CustomEditor() { HasPropertyType = true, PropertyType = typeof(string[]) };
        ComboBoxEditor.Editor = new ComboBoxPropertyGridSample.ComboBoxEditor();

i have also attached simple sample for this 我还附上了简单的样本

http://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboBoxPropertyGridSample1192877556 http://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboBoxPropertyGridSample1192877556

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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