Halt! Halt!
Marina! You need not implement interfaces. Everything is already there.
Ten lines are enough. (well, 20).
(i) Override the Site Property of component A:
public override ISite Site{
get{ return base.Site; }
set{
// get change service
IComponentChangeService chServ = (IComponentChangeService)base.GetService(
typeof( IComponentChangeService));
if( chServ != null){
// may be not the 1st setter call, so unhook:
chServ.ComponentRemoved -= new ComponentEventHandler( chServ_Removed);
}
base.Site = value;
// get anew (the Site is different)
chServ = (IComponentChangeService)base.GetService(
typeof( IComponentChangeService));
// hook
if( chServ != null){
chServ.ComponentRemoved += new ComponentEventHandler( chServ_Removed);
}
}
}
(ii) handle removing:
private void chServ_Removed( object sender, ComponentEventArgs e){
IDesignerHost desHost = (IDesignerHost)sender;
if( desHost.Loading)
return; // all components are removed when designer unloads.
// Ignore in this case. ---------->>>>>>>>>>>>>
if( object.ReferenceEquals( e.Component, this)){
// yes, they want to kill me! Imust kill all my children.
foreach( B b in b_collection){
desHost.DestroyComponent( b);
}
// unhook
IComponentChangeService chServ = (IComponentChangeService)base.GetService(
typeof( IComponentChangeService));
if( chServ != null){
chServ.ComponentRemoved -= new ComponentEventHandler( chServ_Removed);
}
}
}
(iii) be happy.
Check for typos, but the idea must be clear.
It would be better to enclose removing all b-components in one transaction.
(mainly to be able to undo removing in one click).
If i understand what you need.
HTH,
Dima.
[quoted text, click to view] "Marina" <someone@nospam.com> wrote in message news:<utMVQYhUEHA.1472@TK2MSFTNGP09.phx.gbl>...
> Implementing this interface means defining tons of events that don't really
> have anything to do with the component - and then writing an event handler?
>
> I looked at classes like the DataSet - which creates DataTable's in the
> designer. It does not implement this interface.
>
> I am still at a loss at how to actually have the code for these components
> removed from the designer.
>
> Is there a complete example I can look at?
>
> Thanks
>
>
> "DRaiko" <draiko@rhenus.de> wrote in message
> news:3d60d02c.0406140016.25c68a64@posting.google.com...
> > Hi, Marina!
> >
> > Look at ComponentRemoving() / ComponentRemoved() of
> IComponentChangeService.
> > Hook the event (Removed is better, if you dont need to aks the user
> > and prevent removing) in the .Site prop of the component A.
> > You have all you need -- (i) the name of the component going to be deleted
> > so the component can check whether exactly it is killed;
> > and (ii) all pointers to the components (Bs) to remove.
> >
> > You can get IComponentChangeService in .Site calling the GetService()
> > with a propper param. Dont forget to unhook the event when you are ready.
> > Otherwise the component A will not be actually killed and thus
> > the B components also. Consequences can be exciting. But hardly desired.
> >
> > HTH,
> > Dima.
> >
> > "Marina" <someone@nospam.com> wrote in message
> news:<OgaTjN8TEHA.3420@TK2MSFTNGP09.phx.gbl>...
> > > Let's say there is a component (component A) with a collection for a
> > > property. This collection is a collection of components (component B)
> with
> > > DesignTimeVisible = False, so they don't show up in the component tray.
> > >
> > > When adding to the collection, there is a variable declared for each
> > > component B, which is instantiated, etc.
> > >
> > > When A is deleted - all the declarations and instantiations of B stay.
> > >
> > > How to get all the B's deleted, when the A they belong to is deleted?
> > >
> > > Thanks,