K
Kevin Marshall
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;}
}
}
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;}
}
}