This is a migrated thread and some comments may be shown as answers.

[Solved] Node Expand / Selection do different things with Load on Demand enabled

2 Answers 122 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Mark
Top achievements
Rank 1
Mark asked on 22 Dec 2009, 04:25 PM

Requirements
R1.
When the user clicks on a node the LOD (load on demand) occurs and when complete expands its children.
R2. When the user clicks the expansion icon LOD occurs and when completes expands the its children.
Both R1 and R2 should ultimately result in the same feedback to the user.

As of now
R1. Success -This works fine. When the user selects a node in the tree I bubble this up to the viewmodel (PRISM) and your Load On Demand infrustrucure kicks in by presenting the loading icon and once the children have been populated expands the node and removes the loading icon.
R2. Fail

What occurs is that when the user clicks the expansion icon, LoadOnDemand is fired but we don't get the loading icon and when the results come back the node doesn't expand even though the children have been populated. In the end the users feels like they can single click a node but dubble click the expansion icon.

Code in my View

        /// <summary>  
        /// Handles the selection changed event  
        /// </summary>  
        /// <param name="sender">The sender</param>  
        /// <param name="e">The event args</param>  
        private void RadTreeView_Selected(object sender, RadRoutedEventArgs e)  
        {  
            var item = e.Source as RadTreeViewItem;  
            if (item == nullreturn;  
            if (item.IsExpanded) return// Don't load on collapse  
 
            var model = item.Item as HierarchicalModelBase;  
            if (model == nullreturn;  
 
            // Bubble  
            if (ModelSelected != null)  
                ModelSelected(thisnew HierarchicalModelSelectedEventArgs {Model = model});  
        }  
 
        /// <summary>  
        /// Handles the load on demand event  
        /// </summary>  
        /// <param name="sender">The sender</param>  
        /// <param name="e">The event args</param>  
        private void RadTreeView_LoadOnDemand(object sender, RadRoutedEventArgs e)  
        {  
            //// This code exists as for some reason the   
            //// tree does not select the node being expanded.  
            //// This is normal but I can seem to set a   
            //// expand+select switch on the tree  
 
            var item = e.Source as RadTreeViewItem;  
            if (item == nullreturn;  
 
            // Expand the node  
            item.IsSelected = true;  
        } 

2 Answers, 1 is accepted

Sort by
0
Mark
Top achievements
Rank 1
answered on 22 Dec 2009, 07:51 PM
Well, I managed to get this to work but it took some doing. In the end, during an asynch loading (expansion of child nodes) I added an Action to the event so that when the process of loading domain data had finished I could then expand the node. It would be nice to have a property that simply set expanded node to selected then we could route all the loading through the selection code as its this code that performed all this just fine.


        /// <summary>  
        /// Handles the rad tree view item expanded event  
        /// </summary>  
        /// <param name="sender">The sender</param>  
        /// <param name="e">The event args</param>  
        private void RadTreeView_Expanded(object sender, RadRoutedEventArgs e)  
        {  
            // During the expansion event we may need   
            // to load the data for the given node.  
            // We will need to ignore load on demand  
            // nodes as this is handled in the load  
            // on demand event.  
 
            var item = e.Source as RadTreeViewItem;  
            if (item == nullreturn;  
            if (item.IsLoadOnDemandEnabled) return;  
              
            var model = item.Item as HierarchicalModelBase;  
            if (model == nullreturn;  
 
            // Bubble  
            if (ModelExpanded != null)  
                ModelExpanded(thisnew HierarchicalModelSelectedEventArgs { Model = model });  
        }  
 
        /// <summary>  
        /// Handles the selection changed event  
        /// </summary>  
        /// <param name="sender">The sender</param>  
        /// <param name="e">The event args</param>  
        private void RadTreeView_Selected(object sender, RadRoutedEventArgs e)  
        {  
            // During the selection event we may need   
            // to load the data for the given node.  
            // We will need to ignore load on demand  
            // nodes as this is handled in the load  
            // on demand event.  
 
            var item = e.Source as RadTreeViewItem;  
            if (item == nullreturn;  
            if (item.IsLoadOnDemandEnabled) return;  
 
            var model = item.Item as HierarchicalModelBase;  
            if (model == nullreturn;  
 
            // Bubble  
            if (ModelSelected != null)  
                ModelSelected(thisnew HierarchicalModelSelectedEventArgs {Model = model});  
        }  
 
        /// <summary>  
        /// Handles the load on demand event  
        /// </summary>  
        /// <param name="sender">The sender</param>  
        /// <param name="e">The event args</param>  
        private void RadTreeView_LoadOnDemand(object sender, RadRoutedEventArgs e)  
        {  
            var item = e.Source as RadTreeViewItem;  
            if (item == nullreturn;  
 
            var model = item.Item as HierarchicalModelBase;  
            if (model == nullreturn;  
 
 
            // Set post process callback to expnad the   
            // node when the children have been loaded  
            var args = new HierarchicalModelSelectedEventArgs  
                       {  
                           Model = model,  
                           PostProcessCallback =  
                               () =>  
                               {  
                                   item.IsExpanded = true;  
                               }  
                       };  
 
            if (ModelExpanded != null)  
                ModelExpanded(this, args);  
        } 
0
Valentin.Stoychev
Telerik team
answered on 23 Dec 2009, 07:27 AM
Hello Mark,

Please check the online example:
http://demos.telerik.com/silverlight/#TreeView/LoadOnDemand

There the load on demand is working as expected. Please notice that you don't need to set the IsSelected property in the load on demand event handler. You just need to set

currentItem.IsLoadOnDemandEnabled = false;

after the items are added.

You may also need to set the ExpandMode to single click for your scenario. Just set:
IsExpandOnSingleClickEnabled="True".

You can read more info on load on demand feature of the treeview here:
http://www.telerik.com/help/silverlight/radtreeview-features-load-on-demand.html

Greetings,
Valentin.Stoychev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
TreeView
Asked by
Mark
Top achievements
Rank 1
Answers by
Mark
Top achievements
Rank 1
Valentin.Stoychev
Telerik team
Share this question
or