Propagating child events to a collection

  • Thread starter Thread starter Maria
  • Start date Start date
M

Maria

Hi Guys (and Gals)

Bit of a newbie to C# here and I am having a problem which I am coming
across.

I need to capture when events are raised in child objects within a
collection and raise them to the application (I imagine via a proxy
event in the collection class) first of all does anyone have any
sample code, and second can I have it, or at lest how to register the
event in the collection class and then raise it.

TIA

Maria
 
Maria,

This should be pretty easy. I would have two delegates. The first is
exposed as the event that the child fires which the collection picks up:

// The delegate the child event fires.
public delegate void ChildEventHandler(object sender, ChildEventArgs e);

When new instances of the child are created, the parent would connect to
the event that takes this delegate. You then have a second delegate, like
this:

// The delegate that the collection fires.
public delegate void CollectionEventHander(object sender,
CollectionEventArgs e);

Now, the CollectionEventArgs (or whatever you call it), should have a
reference to the child that fired the event, as opposed to the sender being
the child. The reason for this is that the collection is actually firing
the event, and it's good practice to follow the pattern in plage.

Hope this helps.
 
Hi Nicholas

Thanks fo that but, one more question..... how do I register child in
the collection class to get the events propagated.

kind regards

Maria
 
Back
Top