I have a custom class Foo with properties A and B. I want to display it in a databinding control.
I have created a class Foos : BindingList<Foo> .
In order to update some internal properties of the Foos class I need to be notified of property changes (I can handle insertions, removals etc.) on the items in the list. How would you implement that functionality ?
Should I inherit Foo from some object in the framework that supports that ? I think I could create events that notify me if changes, but is that the way it should be done ? Or is there some pattern in the framework, that would help me ?
Foo should implement the
INotifyPropertyChangedandINotifyPropertyChanginginterfaces.The
BindingListshould hook onto your event handler automatically, and your GUI should now update whenever you set your class invokes thePropertyChangedevent handler.[Edit to add:] Additionally, the
BindingListclass expose two events which notify you when the collection has been added to or modified: