做了一个自定义combobox,其中Items属性是这样实现的
private Collection<string> str = new Collection<string>(); public Collection<string> Items
{
get { return str; }
set
{
str = value;
//this.linei = -1;
//this.linej = -1;
this.Invalidate();
this.Update();
}
}
但存在一个问题:缺少combobox.Items.Addrange
如过用private list<string> str = new list<string>();
那么在控件的属性面板上不能添加Items的选择项
怎么才能实现既能在属性面板里添加,又可以添加数组
private Collection<string> str = new Collection<string>(); public Collection<string> Items
{
get { return str; }
set
{
str = value;
//this.linei = -1;
//this.linej = -1;
this.Invalidate();
this.Update();
}
}
但存在一个问题:缺少combobox.Items.Addrange
如过用private list<string> str = new list<string>();
那么在控件的属性面板上不能添加Items的选择项
怎么才能实现既能在属性面板里添加,又可以添加数组
public sealed class ComboBoxItemCollection : IList, ICollection, IEnumerable
{}
里边添加自己的AddRange然后
[MergableProperty(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[EditorAttribute(typeof(CollectionEditor), typeof(UITypeEditor))]
[TypeConverterAttribute(typeof(ComboBoxItemCollection))]
public new ELCComboBoxItemCollection Items{}
{
get { return str; }
set
{
str = value;
//this.linei = -1;
//this.linej = -1;
this.Invalidate();
this.Update();
}
}