What is the best way to update a child control for changes to the parent.
I have several child controls located inside my parent, and I can imagine two ways to send them change information.
1) connect the child control to the event in the parent element and fire this event when the parent changes
2) save the list of children in the array and iterate over the array when this happened, and call the method in the child to handle new changes.
I hope I describe it well.
Both work, but there is probably the right way to handle this and the wrong way.
EDIT: below is my code ... for an event method. I am not happy with the way I connected the child with the parent, and any suggestions.
Parent...
public class A_Parent { public delegate void DelUpdateMessage( string msg ); public event DelUpdateMessage UpdateMessage; public A_Parent() { a_Child1.prnt = this; a_Child2.prnt = this; a_Child3.prnt = this; a_Child4.prnt = this; } private void FireUpdateMessageEvent( string message) { var handlers = UpdateMessage; if (handlers != null) handlers( message ); } }
Child...
public class A_Child { A_Parent pnt; public A_Parent prnt { set { pnt = value; pnt.UpdateMessage += new A_Parent.DelUpdateMessage(pnt_UpdateMessage); } } void pnt_UpdateMessage(string msg) { } }
source share