.net - ListChanged Event when property of a custom class in binding list changes -


i have bindinglist (bindinglist (of foo)) several objects of sample class:

class foo implements inotifypropertychanged  private _name string private _numer integer private _otherclass otherclass private _bindinglistofanotherclass bindinglist (of anotherclass)  end class 

now want informed, when property of item in bindinglist changes.

as can see, have interface implemented , i'm throwing events. listchanged events thrown primitive properties not if property in otherclass or in anotherclass changes (or if item added / removed in _bindinglistofanotherclass).

i'm throwing propertychanged events in otherclass , anotherclass.

any idea?

unfortunately there no auto-wireup foo class know when otherclass changes unless foo listens propertychanged event of otherclass subscribing event handler. in event handler fire property changed event on foo saying otherclass property has changed.

this can little tricky because if property exposed getter/setter of kind, need unsubscribe , resubscribe object changes.

in case of bindinglist of anotherclass, it's bit different since bindinglist not implement inotifypropertychanged. implements ibindinglist has listchanged event. have subscribe that.

as long anotherclass implements inotifypropertychanged, binding list should throw changed event foo, can in turn throw own propertychanged event.

edit:

here how handle properties can change want subscribe events:

private object _myobject; public object myobject {         {         return _myobject;     }     set     {         if (_myobject != value)         {             if (_myobject != null)                 _myobject.propertychanged -= mydelegate;              _myobject = value;              if (_myobject != null)                 _myobject.propertychanged += mydelegate;         }     } } 

this way can safely set null value , null again , manage event subscriptions you.


Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -