The following code example shows use the CollectionBase to add items and the owner control is updated on insert\remove\delete.
public class ImagesCollection : CollectionBase
{
private ListControl _ownerControl;
public ImagesCollection(ListControl ownerControl)
{
_ownerControl = ownerControl;
}
public ImageHolder this[int index]
{
get
{
return ((ImageHolder)List[index]);
}
set
{
List[index] =
value;
}
}
public int Add(ImageHolder value)
{
return (List.Add(value));
}
public int IndexOf(ImageHolder value)
{
return (List.IndexOf(value));
}
public void Insert(int index, ImageHolder value)
{
List.Insert(index, value);
}
public void Remove(ImageHolder value)
{
List.Remove(value);
}
public bool Contains(ImageHolder value)
{
return (List.Contains(value));
}
protected override void OnInsert(int index, Object value)
{
// Insert additional code to be run only when inserting values.
_ownerControl.UpdateElements();
}
protected override void OnRemove(int index, Object value)
{
// Insert additional code to be run only when removing values.
_ownerControl.UpdateElements();
}
protected override void OnSet(int index, Object oldValue, Object newValue)
{
// Insert additional code to be run only when setting values.
_ownerControl.UpdateElements();
}
protected override void OnValidate(Object value)
{
if (value.GetType() != typeof(ImageHolder))
throw new ArgumentException("value must be of type ImageHolder.", "value");
}
}
On the collection ctor, you need to send the onwer control (your CustomToolStrip) and on the update events (insert\remove\set), call the UpdatePanels() method you have in your control, the one that adds panels.