Updating the TreeView when business object changes
Hello!
Once again, I have a question regarding design of the code. Let me explain the situation:
I have a hierarchical list of business objects, that I want to show in a TreeView. The number of elements and levels can vary, from only a couple to hundreds of objects. It has the following structure:
Code:
content list class
|__content item
|__content item
|__content item
| |__content item child
| |__content item child
| .......
|__content item
.....
After populating the TreeView, the list and object properties that it reflects can of course change. I can, of course, re-populate the whole TreeView, but that gets slow. So I want to notify the TreeView about each particular change, so it could process just the node that has changed.
I'm wondering, what, in your opinion, is the best way to notify the TreeView about list and object changes?
I'm of course aware, that I can use events in every object and collection I use, but that involves subscribing to hundreds of events. As I examined the TreeView control a little bit more, it has general events, like 'NodeMouseClick', 'NodeMouseHover', etc., that passes the node that caused the event to the delegate.
So I'm wondering if it is a good way to use single event at the highest level of my object hierarchy to handle events of all the child objects? The best way I can imagine is to create a method that raises the event in the top level collection and call it from the child objects, but it must be a public method then (or internal, but that doesn't change anything, since there are other application layers in the same assembly) so I have a little doubt about this. Should I really expose a method that raises an event to the public?.. I'm confused and haven't found a solution on google yet :/
I'd be grateful if you could share your experience on this matter :)
Re: Updating the TreeView when business object changes
It is relatively unusual to put disparate unrelated types into a TreeView. After all, they should have some type of relation...
The general approach is to use events on the Business Objects, Ideally in a manner that provides one homogonous event structure across the different types. In many cases the use of a Facade or Adapter pattern may make the task easier....
Re: Updating the TreeView when business object changes
Quote:
Originally Posted by
TheCPUWizard
It is relatively unusual to put disparate unrelated types into a TreeView. After all, they should have some type of relation...
I'm sorry if didn't describe it clearly. All the objects implement an interface IContentListItem and have a collection of IContentListItems too. The ContentList class is basically the root element of the whole list.
The reason I'm afraid of having events in every object is that I think it might get really slow when there will be a couple of hundreds of nodes.
Re: Updating the TreeView when business object changes
Quote:
Originally Posted by
gecka
I'm sorry if didn't describe it clearly. All the objects implement an interface IContentListItem and have a collection of IContentListItems too. The ContentList class is basically the root element of the whole list.
The reason I'm afraid of having events in every object is that I think it might get really slow when there will be a couple of hundreds of nodes.
Have you tested it? I would avoid assuming that something is slow until you know that it is. Remember, premature optimization is the root of all evil.