Load-On-Demand tree View does not refresh when a new item is added

2 posts, 0 answers
  1. Maria Im
    Maria Im avatar
    10 posts
    Member since:
    Sep 2012

    Posted 17 Jan 2011 Link to this post

    I have a treeview (see image attached) that does not refresh when I add an item. We use the WPF MVVM framework.
    When the tree loads the first time, the treeview works perfectly. When clicking on each item, it successfully loads its sub item correctly. Now if i decide to add a sub_item to a level that I selected, For example let's say i want to add a Client vist date to treatments. So my treatment Level would be selected, I would click an add button and will create a Client Visit. After completion, I want the tree to refresh (using that load-on-demand functionality) and show me my new added Client Visit under the treatment I selected. unfortunately, this does not work. with the Load-On-Demad functionality. It seems to work only ONCE and that is when the tree is first loaded. After that it never triggers any of item_prepared, load_on_demand events until restart the application to see my changes. Please could you help in showing me, using MVVM WPF (not silverlight) how:
    1) to store the item path
    2) After adding an item to the treeview, refresh the tree (using load on-demand) to display the new item that was added
    Thank you. This is needed so urgently. I would appreciate a fast response. Thank you again
  2. Petar Mladenov
    Petar Mladenov avatar
    2985 posts

    Posted 20 Jan 2011 Link to this post

    Hi Maria Im,

    I prepared a project for you to illustrate the common use of LoadOndemand and ExpandItemByPath.
    The LoadOnDemand feature is used when you expand a RadTreeViewItem and you want to add new Items ( business items or RadTreeViewitems )  right after the node is expanded. When you add new Items via other methods ( for example Button`s Click handler) and you wish to view the changes in the visual tree you have to use the ExpandItemByPath Method. Using LOD or not, UI Virtualization or not, the visual containers (RadTreeViewItems)  are generated  only when they are needed. When the tree loads, only the root level is generated and ItemPrepared fires for every item in the root level. Then ItemPrepared fires when you expand an item that has children or when you add an item to a level that is already revealed.
    In the attached solution you can use the LOD feature by expanding an item via mouse click and you can programmatically add an item to the SelectedItem of the tree( if exist). Note that the LOD feature is stopped before and started after the ExpandItemByPath method.
    Hope this helped you. Feel free to ask if you need more info.

    Kind regards,
    Petar Mladenov
    the Telerik team
    Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Back to Top