Using CollectionBase
-
Hello!! I have created my own collection :
[TypeConverter(typeof(MyCollectionConverter))] public class MyCollection { private Color color1 = Color.White; private Color color2 = Color.Black; private int value1 = 0; private int value2 = 0; private bool blink = false; private bool visible = true; private string nname = string.Empty; [Browsable(true)] public Color Color1 { get { return color1; } set { color1 = value; } } [Browsable(true)] public Color Color2 { get { return color2; } set { color2 = value; } } [Browsable(true)] public int Value1 { get { return value1; } set { value1 = value; } } [Browsable(true)] public int Value2 { get { return value2; } set { value2 = value; } } [Browsable(true)] public bool Blink { get { return blink; } set { blink = value; } } [Browsable(true)] public bool Visible { get { return visible; } set { visible = value; } } [Browsable(true)] public string Name { get { return name; } set { name = value; } } public MyCollection() { } }
public class MyCollectionConverter : CollectionBase { public MyCollectionConverter () { } public int Add(MyCollectione) { return this.InnerList.Add(e); } public void AddRange(MyCollection[] es) { this.InnerList.AddRange(es); } public void Remove(MyCollectione) { InnerList.Remove(e); } public new void RemoveAt(int index) { InnerList.RemoveAt(index); } public bool Contains(MyCollection e) { return InnerList.Contains(e); } public MyCollection this[int index] { get { return (MyCollection)this.InnerList[index]; } set { this.InnerList[index] = value; } } }
and in a click event i add some elements to the collection like this: MyCollectionConverter -
Hello!! I have created my own collection :
[TypeConverter(typeof(MyCollectionConverter))] public class MyCollection { private Color color1 = Color.White; private Color color2 = Color.Black; private int value1 = 0; private int value2 = 0; private bool blink = false; private bool visible = true; private string nname = string.Empty; [Browsable(true)] public Color Color1 { get { return color1; } set { color1 = value; } } [Browsable(true)] public Color Color2 { get { return color2; } set { color2 = value; } } [Browsable(true)] public int Value1 { get { return value1; } set { value1 = value; } } [Browsable(true)] public int Value2 { get { return value2; } set { value2 = value; } } [Browsable(true)] public bool Blink { get { return blink; } set { blink = value; } } [Browsable(true)] public bool Visible { get { return visible; } set { visible = value; } } [Browsable(true)] public string Name { get { return name; } set { name = value; } } public MyCollection() { } }
public class MyCollectionConverter : CollectionBase { public MyCollectionConverter () { } public int Add(MyCollectione) { return this.InnerList.Add(e); } public void AddRange(MyCollection[] es) { this.InnerList.AddRange(es); } public void Remove(MyCollectione) { InnerList.Remove(e); } public new void RemoveAt(int index) { InnerList.RemoveAt(index); } public bool Contains(MyCollection e) { return InnerList.Contains(e); } public MyCollection this[int index] { get { return (MyCollection)this.InnerList[index]; } set { this.InnerList[index] = value; } } }
and in a click event i add some elements to the collection like this: MyCollectionConverterYou might want to try overriding OnInsert and OnRemove and unconditionally throw an exception. The designer should catch that exception and display a messagebox to the user after he/she clicks the Add or Remove buttons. Josh