Subscribe child controls to events
Posted on 2006-04-20
I am in the process of writing a database-connected application. I am using a base "data entry" form from which all data forms derive. On the derived forms, I add a series of controls which get bound to database objects.
On each form, I have subscribed all the child controls to a "value changed" event of some sort (text changed for textboxes, checkedChanged for checkboxes, etc.) which in turn update a boolean indicating whether the user has changed data on the page since its inception (checking the underlying dataSet for changes will sometimes return true even if the data didn't actually "change", such as adding a blank row to emulate a "new" entry). The "value change" events are the same for all textboxes, checkboxes, etc.
What I would like to do is create a method in my base form which automatically subscribes child controls to their specific value change event. I don't like the method of doing this on each derived form, since its allows too much variation between forms and does not create a consistent UI (nevermind the excessive extra work it requires).
Is there a way to subscribe child to controls to an event, and possibly also subscribe "children of children" to events as well? Iff so, how would I go about subscribing child controls to their specified events in the base form rather than each derived form?