Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Using CollectionBase

Using CollectionBase

Scheduled Pinned Locked Moved C#
database
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JuanAlbertoMD
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • J JuanAlbertoMD

      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

      J Offline
      J Offline
      Josh Smith
      wrote on last edited by
      #2

      You 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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups