I am trying to learn more about BindingList because I believe that it will help me with a project that I am working on.
Currently, I have an object class (ScannedImage) that is a subtype of a class (HashedImage) that subtypes a native .Net object (Image). There is no reason why I couldn’t move the two subtypes together. I am simply subtyping an object that I had previously constructed, but I will now be storing my ScannedImage object in an RDB (well, not technically – only the details and probably the thumbnail).
Also, the object class has member types that are my own custom types (Keywords). I am using a custom datagridview to present these objects, but am handling all changes to the ScannedImage object with my own code. As you can probably imagine, I have quite a few events to handle that occur in these base types.
So, if I changed my object to implement INotifyPropertyChanged, would the object collection (implementing BindingList) receive notifications of changes to the ScannedImage object?
Also, if Keywords were to implement INotifyPropertyChanged, would changes be accessible to the BindingList through the ScannedImage object?
Sorry if this seems rather newbish. I only recently discovered the BindingList and not having formal training in C# programming – am having a difficult time moving forward with this.
Also, if anyone has any good reference material, I would be thankful for links. Obviously, I have perused the MSDN Library. I have found a few good links on the web, but it seems that a lot of people are now using WPF and ObservableCollection.
My project is based on Winforms and .Net3.5 framework.
TIA
I’ll answer both of your questions:
If you actually use the
BindingList<T>class insideSystem.ComponentModel, then it does contain special-case code for elements that impelmentINotifyPropertyChanged. The list will see the property changes and will send out notifications.However, you specifically ask about “implementing BindingList” which is subtly different. You can’t implement a class. But there is an interface,
IBindingList, that you can implement with your own class, and if this is the route you choose to take, then it becomes your responsibility when you write the list class to ensure that you monitor for property change notifications.Generally you shouldn’t need to create your own
IBindingListimplementation; just useBindingList<T>to wrap an existing list and you’ll be fine.No, they will not.
BindingList<T>only looks at the specific object in the list, it has no ability to scan all dependencies and monitor everything in the graph (nor would that always be a good idea, if it were possible).What you’ll have to do if you want to receive notifications is update your
ScannedImageclass to check for property change notifications from theKeywordsobject, then fire its ownPropertyChangedevent in response.Example:
I hope you understand what’s being done here. The owner,
ScannedImage, automatically hooks thePropertyChangedevent from its innerKeywordsclass and raises a separate property changed event saying that theKeywordshave changed. This way, binding lists and other data binding controls will receive notification when the keywords change.