From: Joe Cool on
On Jan 22, 1:44 pm, Mike <MLM...(a)hotmail.com> wrote:
> On Jan 22, 1:24 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
>
> h...(a)gmx.at> wrote:
> > Am 22.01.2010 16:52, schrieb Mike:
>
> > > Is there a way to detect when the parent of a control is about to
> > > change? I am aware of the ParentChanged event but that happens too
> > > late. I don't see any ParentChanging event.
>
> > Why exactly does it happen too late?  What do you want to achieve?
>
> > --
> >   M S   Herfried K. Wagner
> > M V P  <URL:http://dotnet.mvps.org/>
> >   V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
> There is some clean up work that I need to do before the control is
> removed. If I wait for the ParentChanged event, the parent will be
> null and I get errors.

If the control is being removed by code, then can't the code that
removes it then perform the cleanup?
From: Mike on
On Jan 22, 1:53 pm, Joe Cool <joecool1...(a)live.com> wrote:
> On Jan 22, 1:44 pm, Mike <MLM...(a)hotmail.com> wrote:
>
>
>
>
>
> > On Jan 22, 1:24 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
>
> > h...(a)gmx.at> wrote:
> > > Am 22.01.2010 16:52, schrieb Mike:
>
> > > > Is there a way to detect when the parent of a control is about to
> > > > change? I am aware of the ParentChanged event but that happens too
> > > > late. I don't see any ParentChanging event.
>
> > > Why exactly does it happen too late?  What do you want to achieve?
>
> > > --
> > >   M S   Herfried K. Wagner
> > > M V P  <URL:http://dotnet.mvps.org/>
> > >   V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
> > There is some clean up work that I need to do before the control is
> > removed. If I wait for the ParentChanged event, the parent will be
> > null and I get errors.
>
> If the control is being removed by code, then can't the code that
> removes it then perform the cleanup?- Hide quoted text -
>
> - Show quoted text -

That would require that every person using my control needs to know to
do that. I'd much rather do something automated.
From: Peter Duniho on
Mike wrote:
> On Jan 22, 1:24 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
> h...(a)gmx.at> wrote:
>> Am 22.01.2010 16:52, schrieb Mike:
>>
>>> Is there a way to detect when the parent of a control is about to
>>> change? I am aware of the ParentChanged event but that happens too
>>> late. I don't see any ParentChanging event.
>> Why exactly does it happen too late? What do you want to achieve?
>>
>> --
>> M S Herfried K. Wagner
>> M V P <URL:http://dotnet.mvps.org/>
>> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
> There is some clean up work that I need to do before the control is
> removed. If I wait for the ParentChanged event, the parent will be
> null and I get errors.

AFAIK, you can't get the notification you want.

Without more specifics, it's unclear as to what details you have that
are dependent on the parent, nor why you're not able to rely on the code
that is actually changing the parent. These may or may not be design
problems.

But purely from the practical side of things, it seems that you will
need to retain a reference to the parent control elsewhere, so that you
still have access to it after the Parent property changes.

Pete
From: Mike on
On Jan 22, 1:55 pm, Peter Duniho <no.peted.s...(a)no.nwlink.spam.com>
wrote:
> Mike wrote:
> > On Jan 22, 1:24 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
> > h...(a)gmx.at> wrote:
> >> Am 22.01.2010 16:52, schrieb Mike:
>
> >>> Is there a way to detect when the parent of a control is about to
> >>> change? I am aware of the ParentChanged event but that happens too
> >>> late. I don't see any ParentChanging event.
> >> Why exactly does it happen too late?  What do you want to achieve?
>
> >> --
> >>   M S   Herfried K. Wagner
> >> M V P  <URL:http://dotnet.mvps.org/>
> >>   V B   <URL:http://dotnet.mvps.org/dotnet/faqs/>
>
> > There is some clean up work that I need to do before the control is
> > removed. If I wait for the ParentChanged event, the parent will be
> > null and I get errors.
>
> AFAIK, you can't get the notification you want.
>
> Without more specifics, it's unclear as to what details you have that
> are dependent on the parent, nor why you're not able to rely on the code
> that is actually changing the parent.  These may or may not be design
> problems.
>
> But purely from the practical side of things, it seems that you will
> need to retain a reference to the parent control elsewhere, so that you
> still have access to it after the Parent property changes.
>
> Pete- Hide quoted text -
>
> - Show quoted text -

Saving the property elsewhere does not solve my problem since the
object that looks for the parent is in a 3rd party assembly. Anyway,
thanks for the answer to the original question. I will have to see if
I can find a different approach.
From: Peter Duniho on
Mike wrote:
> Saving the property elsewhere does not solve my problem since the
> object that looks for the parent is in a 3rd party assembly.

That makes little sense to me. _Whatever_ the code that "looks for the
parent", that would be the code that would save the old value. No
matter where that code is, it can do it.

> Anyway,
> thanks for the answer to the original question. I will have to see if
> I can find a different approach.

Well, I strongly suspect that you've got a more fundamental design
problem. So my advice would be to look more carefully at whatever
strategy you're trying to implement now, to try to identify a simpler,
more conforming approach that would work better.

My experience has been, when I find that the API or framework I'm using
doesn't support some specific usage scenario I'm trying to implement,
it's usually because whatever design I've come up with that requires
that usage scenario is flawed.

Pete