PropertyGrid 添加ComboBox 笨笨的办法

定义实体:

using System; using System.Collections.Generic; using System.Text; using System.ComponentModel; using System.Collections; namespace Test.Models { [Serializable] public class TestModel { private string _期限; // 分类显示 描述 显示名称 [CategoryAttribute("档案属性"), DescriptionAttribute("期限"), DisplayName("期限")] [TypeConverter(typeof(ComboBoxItemRecordLimit))] public string 期限 { get { return _期限; } set { _期限 = value; } } } public class ComboBoxItemRecordLimit: TypeConverter { private ArrayList _values = null; public static ArrayList Alist = new ArrayList(); public ComboBoxItemRecordLimit() { this._values = Alist; } public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { return new StandardValuesCollection(this._values); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) return true; return base.CanConvertFrom(context, sourceType); } public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value) { if (value is string) { return value.ToString(); } return base.ConvertFrom(context, culture, value); } } }

使用方法:

//实体 TestModel test = new TestModel (); Arec.期限 = "永久"; //期限 ComboBoxItemRecordLimit.Alist.Clear(); ComboBoxItemRecordLimit.Alist.Add("永久"); ComboBoxItemRecordLimit.Alist.Add("长期"); ComboBoxItemRecordLimit.Alist.Add("短期"); this.ppgrid1.SelectedObject = test ;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值