vb.net - how to pass an event from a child object in a generic list to the parent? -


here example code:

public class parent     private _testproperty string     private withevents _child ilist(of child)      public property test() string                     return _testproperty         end         set(byval value string)             _testproperty = value         end set     end property      public property child() ilist(of child)                     return _child         end         set(byval value ilist(of child))             _child = value         end set     end property      private sub eventhandler handles _child end class  public class child     private _testproperty string     public event propertychanged eventhandler      friend sub notify()         raiseevent propertychanged(me, new eventargs())     end sub      public property test() string                     return _testproperty         end         set(byval value string)             _testproperty = value             notify()         end set     end property end class 

how can handle event raised 1 of child`s in parent object? using withevents on _child object gives me events list(of t) object.

tia

if you, implement ilist in parent using aggregated typed list, subscribing child events on ilist.add , unsubscibing on remove. (sorry c# syntax).

class child {   public event eventhandler myevent; }  class parent : ilist<child> {   list<child> _list;    // ilist implementation   // ...   public void add(child item)   {      item.myevent += _parentchildeventhandler;      _list.add(item);     }    public void remove(child item)   {     item.myevent -= _parentchildeventhandker;     _list.remove(item);   }    void _parentchildeventhandler(object sender, eventargs e)   {     child child = (child)sender;      // write event handling code here   } } 

Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -