Subject: Accessing parent control functions from child
Posted By: badgolfer Post Date: 1/7/2004 7:53:02 AM

VB.NET app question

I have created myself a simple user control ( consisting of a few
edit boxes etc ). I use this user control on several different
forms within my application. I simply create instances of my
user control and assign them as children of my various parent
form(s).

My question - what is the best way to call a user defined
function/sub in the parent form from my child user control ?

I do not always need to do this - it depends on the type of
parent form in which I have embedded my child control. But sometimes
I need to tell my parent form that there has been a status
change within its child control.

Any ideas on best practice?


Reply By: planoie Reply Date: 1/7/2004 10:54:18 AM
Instead of thinking of this as "How do I call a method in my parent?" think of it as "How do I TELL my parent something happened?".

The child control should offer an event for the status change you speak of.  Create a public event in the control and then the containing parent form (or control) can handle that event as it wants (or not at all).  This way, if the control is on a form/control that doesn't care about that event, the child control won't break because instead of calling a function that doesn't exist, it's just raising the event.

This technique follows the event driven model that all the .net controls follow.

Peter
------------------------------------------------------
Work smarter, not harder.
Reply By: badgolfer Reply Date: 1/9/2004 6:49:57 AM
Thanks Peter - I understand the event raising/handling now.

Go to topic 8369

Return to index page 973
Return to index page 972
Return to index page 971
Return to index page 970
Return to index page 969
Return to index page 968
Return to index page 967
Return to index page 966
Return to index page 965
Return to index page 964