Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / January 2008

Tip: Looking for answers? Try searching our database.

Calling the parent

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Arne Garvander - 24 Jan 2008 17:47 GMT
I have a user control inside another user control.
Is there a way for a Child Control to call back to the parent, raising an
event in the parent or anything such?
Signature

Arne Garvander
Certified Geek
Professional Data Dude

Jack Jackson - 24 Jan 2008 20:19 GMT
>I have a user control inside another user control.
>Is there a way for a Child Control to call back to the parent, raising an
>event in the parent or anything such?

You don't raise an event in another object.  You raise an event in
your object and any other objects that have subscribed to that event
get called.  In this case the child control would have to define an
event and the parent would need to subscribe to that event.

You can access methods and properties in the parent.  If the parent is
an instance of SomeClass or implements a known interface:

Dim myParent As SomeClass = TryCast(Me.Parent, SomeClass)
If myParent IsNot Nothing Then
  myParent.SomeMethod()
...

Interfaces are probably the best way to deal with this, then the child
doesn't have to know the exact class of the parent, you just have to
make sure that all classes that might be the child's parent implement
the interface.
Doug Holland - 25 Jan 2008 20:45 GMT
I agree with Jack that interfaces are certainly the best answer. I've also
found that creating a class that derives from ApplicationContext is useful as
you can expose an internal property that allows any code in your application
to access the applications main form. The custom ApplicationContext is also a
great place to store other application wide information that might be useful
throughout the application. Personally I implement the ApplicationContext as
a singleton with static properties to access the application wide details
that are cached at startup.

> >I have a user control inside another user control.
> >Is there a way for a Child Control to call back to the parent, raising an
[quoted text clipped - 17 lines]
> make sure that all classes that might be the child's parent implement
> the interface.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.