做了一个自定义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的选择项
怎么才能实现既能在属性面板里添加,又可以添加数组

解决方案 »

  1.   

    自己写一个
    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{}
      

  2.   

    可以到codeproject.com找找 看看别人怎么做的
      

  3.   

    直接使用ObjectCollection.        private ObjectCollection str = new ObjectCollection(null);        public new ObjectCollection Items
            {
                get { return str; }
                set
                {
                    str = value;
                    //this.linei = -1; 
                    //this.linej = -1; 
                    this.Invalidate();
                    this.Update();                
                }
            }
      

  4.   

    楼上的  我的代码中有很多Item[i] 都报错
      

  5.   

    items直接用ComboBox.ObjectCollection 类型的不可以吗?