PC Review


Reply
Thread Tools Rate Thread

Detecting when parent is about to change

 
 
Mike
Guest
Posts: n/a
 
      22nd Jan 2010
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.

Thanks,
Mike
 
Reply With Quote
 
 
 
 
Joe Cool
Guest
Posts: n/a
 
      22nd Jan 2010
On Jan 22, 10:52*am, Mike <MLM...@hotmail.com> wrote:
> 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.
>
> Thanks,
> Mike


Just what is causing the parent to change?
 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      22nd Jan 2010
On Jan 22, 12:03*pm, Joe Cool <joecool1...@live.com> wrote:
> On Jan 22, 10:52*am, Mike <MLM...@hotmail.com> wrote:
>
> > 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.

>
> > Thanks,
> > Mike

>
> Just what is causing the parent to change?


Any time the control is added to or removed from a control/form.
 
Reply With Quote
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      22nd Jan 2010
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/>
 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      22nd Jan 2010
On Jan 22, 1:24*pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
h...@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.
 
Reply With Quote
 
Joe Cool
Guest
Posts: n/a
 
      22nd Jan 2010
On Jan 22, 1:44*pm, Mike <MLM...@hotmail.com> wrote:
> On Jan 22, 1:24*pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
>
> h...@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?
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      22nd Jan 2010
Mike wrote:
> On Jan 22, 1:24 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
> h...@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
 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      22nd Jan 2010
On Jan 22, 1:53*pm, Joe Cool <joecool1...@live.com> wrote:
> On Jan 22, 1:44*pm, Mike <MLM...@hotmail.com> wrote:
>
>
>
>
>
> > On Jan 22, 1:24*pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-

>
> > h...@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.
 
Reply With Quote
 
Mike
Guest
Posts: n/a
 
      22nd Jan 2010
On Jan 22, 1:55*pm, Peter Duniho <no.peted.s...@no.nwlink.spam.com>
wrote:
> Mike wrote:
> > On Jan 22, 1:24 pm, "Herfried K. Wagner [MVP]" <hirf-spam-me-
> > h...@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.
 
Reply With Quote
 
Peter Duniho
Guest
Posts: n/a
 
      22nd Jan 2010
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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Detecting when parent is about to change Mike Microsoft C# .NET 14 25th Jan 2010 01:18 AM
Detecting a value change in a control rhardy Microsoft Access VBA Modules 9 12th Mar 2009 04:52 PM
detecting change A Benn Microsoft Excel Discussion 1 30th Sep 2004 12:18 PM
detecting a change in a datagrid Robert Batt Microsoft ADO .NET 2 27th Aug 2003 02:19 PM
Re: datagrids - detecting a change Jeremy Cowles Microsoft VB .NET 0 26th Aug 2003 05:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:46 AM.