CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2006
    Posts
    97

    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
    Last edited by gecka; January 13th, 2009 at 02:35 PM.
    Using .NET 2.0

  2. #2
    Join Date
    Mar 2002
    Location
    St. Petersburg, Florida, USA
    Posts
    12,125

    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....
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009,2010
    In theory, there is no difference between theory and practice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  3. #3
    Join Date
    Jul 2006
    Posts
    97

    Re: Updating the TreeView when business object changes

    Quote Originally Posted by TheCPUWizard View Post
    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.
    Using .NET 2.0

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Updating the TreeView when business object changes

    Quote Originally Posted by gecka View Post
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured