Strange Collection Editor Problem

Discussion in 'ASP .Net Building Controls' started by Kevin Marshall, Mar 17, 2005.

  1. I am having problems with collection editor properties on my controls, the
    problem seems to be that I can add items and set properties no problem but
    often when removing an item or even clearing an items property value it
    appears to work but it really does not work, I can see this by viewing the
    HTML.

    If I close the page and open it the old values show up in the collection
    editor. the strangest thing is that half the time it all work as it should,
    does anyone have a clue what could cause the problem?

    I have included sample code showing what I am doing, the collectionitems in
    the real controls have many more properties than the 2 in this sample.

    Thanks in advance to anyone who can help.

    Kevin Marshall


    /////////// MyControl Class /////////////

    [
    ToolboxItemAttribute(false),
    DefaultEvent("Load"),
    ParseChildren(true),
    PersistChildren(false),
    ToolboxData("<{0}:MyControl runat=server></{0}:MyControl>")
    ]
    public class MyControl: WebControl, INamingContainer
    {
    private MyCollection i_MyCollection = new MyCollection();
    [Category("Data"),DefaultValue(null),MergableProperty(false),PersistenceMode(PersistenceMode.InnerProperty)]
    public MyCollection MyCollection
    {
    get{return i_MyCollection;}
    }
    }


    /////////// MyCollection Class /////////////
    [ToolboxItemAttribute(false)]
    public class MyCollection : ICollection, IEnumerable, IList
    {
    private ArrayList MyCollCollection;
    public MyCollection(){MyCollCollection = new ArrayList();}
    object IList.this[int index]
    {
    get{return MyCollCollection[index];}
    set{MyCollCollection[index] = (CollectionItem)value;}
    }
    public int Count
    {
    get{return MyCollCollection.Count;}
    }
    public bool IsSynchronized
    {
    get{return true;}
    }
    public object SyncRoot
    {
    get{return MyCollCollection.SyncRoot;}
    }
    public void CopyTo (Array ar, int index)
    {
    }
    public virtual CollectionItem this[int index]
    {
    get{return (CollectionItem)MyCollCollection[index];}
    set{MyCollCollection[index] = value;}
    }
    public void Remove (object item)
    {
    MyCollCollection.Remove (item);
    }
    public void Insert (int index, object item)
    {
    MyCollCollection[index] = item;
    }
    public int Add (object item)
    {
    return MyCollCollection.Add(item);
    }
    public void Clear()
    {
    MyCollCollection.Clear();
    }
    public bool Contains(object item)
    {
    return MyCollCollection.Contains(item);
    }
    public int IndexOf (object item)
    {
    return MyCollCollection.IndexOf(item);
    }
    public bool IsFixedSize
    {
    get{return false;}
    }
    public bool IsReadOnly
    {
    get{return false;}
    }
    public void RemoveAt(int index)
    {
    MyCollCollection.RemoveAt(index);
    }

    public virtual IEnumerator GetEnumerator()
    {
    return MyCollCollection.GetEnumerator();
    }
    }

    /////////// CollectionItem Class /////////////
    [ToolboxItemAttribute(false)]
    public class CollectionItem : Control
    {
    public CollectionItem()
    {
    ID = null;
    }
    private string i_MyProp1 = "";
    [Category("Caption"),DefaultValue("")]
    public string MyProp1
    {
    get{return i_MyProp1;}
    set{i_MyProp1 = value;}
    }
    private string i_MyProp2 = "";
    [Category("Field Names"),DefaultValue("")]
    public string MyProp2
    {
    get{return i_MyProp2;}
    set{i_MyProp2 = value;}
    }
    [DefaultValue(null),Browsable(false)]
    public override string ID
    {
    get{return null;}
    set{base.ID = null;}
    }
    }

    --
    Kevin Marshall
    Kevin Marshall, Mar 17, 2005
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stylus Studio
    Replies:
    0
    Views:
    634
    Stylus Studio
    Aug 3, 2004
  2. Dylan
    Replies:
    5
    Views:
    410
    Daniel T.
    Mar 22, 2005
  3. Pradeep
    Replies:
    2
    Views:
    669
    Patricia Shanahan
    Jan 24, 2007
  4. Øyvind Isaksen
    Replies:
    1
    Views:
    946
    Øyvind Isaksen
    May 18, 2007
  5. Replies:
    1
    Views:
    274
    Tim Dot NoSpam
    May 19, 2006
Loading...

Share This Page