簡體   English   中英

將屬性更改為propertygrid中的組合框

[英]change property to combobox in propertygrid

我有來自互聯網源代碼的這段代碼,我認為這段代碼可能適用於將屬性從文本框更改為PropertyGrid中的組合框,但在運行之后,它仍然是一個文本框。 有人可以幫忙解決這個問題嗎?

 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);
        }
    }
}

如果我們需要從TextBox到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();

我還附上了簡單的樣本

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM