Depending on your intent, you may need to implement a custom designer. If
your collection is of classes inherited from Components, it's quite easy.
All you have to do is catch the ComponentRemoving/ComponentRemoved events
from IComponentChangeService. Here's some code I have lying around.
public class DteAddInDesigner : ComponentDocumentDesigner
{
private DteAddIn _addIn;
protected override void Dispose(bool disposing)
{
if (disposing)
{
IComponentChangeService c = (IComponentChangeService)
GetService(typeof(IComponentChangeService));
c.ComponentAdded -= new ComponentEventHandler(OnComponentAdded);
c.ComponentRemoving -= new ComponentEventHandler(OnComponentRemoving);
c.ComponentRename -= new ComponentRenameEventHandler(OnComponentRename);
}
base.Dispose(disposing);
}
public override void Initialize(System.ComponentModel.IComponent component)
{
base.Initialize(component);
// Record instance of control we're designing
_addIn = (DteAddIn) component;
// Hook up events
IComponentChangeService c = (IComponentChangeService)
GetService(typeof(IComponentChangeService));
c.ComponentAdded += new ComponentEventHandler(OnComponentAdded);
c.ComponentRemoving += new ComponentEventHandler(OnComponentRemoving);
c.ComponentRename += new ComponentRenameEventHandler(OnComponentRename);
}
public override void OnSetComponentDefaults()
{
_addIn.Text = _addIn.Site.Name;
base.OnSetComponentDefaults ();
}
private void OnComponentAdded(object sender, ComponentEventArgs e)
{
}
private void OnComponentRemoving(object sender, ComponentEventArgs e)
{
}
private void OnComponentRename(object sender, ComponentRenameEventArgs e)
{
}
}
[quoted text, click to view] "Greg" <gdog@nospam.nospam> wrote in message
news:%23fDxWrKOGHA.2828@TK2MSFTNGP12.phx.gbl...
>I have a control derived from UserControl with a collection member. When
>the designer invokes its collection editor and the developer adds/removes
>items, can I get notified of that in my control? When they hit OK on the
>collection editor dialog, I'd like to invoke some of my code. How do I do
>that?
>