IsVirtualizing & LoadOnDemand issue

3 posts, 0 answers
  1. Josh
    Josh avatar
    27 posts
    Member since:
    Feb 2012

    Posted 19 Sep 2012 Link to this post

    We have discovered an issue in the TreeView for instances where IsVirtualizing is set to true and LoadOnDemand is enabled where the tree view ignores the OptionType setting for newly created items.

    When the page loads, we loop through a collection of items and add them to the tree like so:

    RadTreeViewItem itineraryTreeViewItem = new RadTreeViewItem
                            DataContext = foo,
                            Header =,
                            OptionType = OptionListType.CheckList,
                            IsLoadOnDemandEnabled = true
    itineraryTreeViewItem.LoadOnDemand += Treeview_LoadOnDemand;

    The pertinent code for the Treeview_LoadOnDemand method is below.  I simplified it some as our actual code checks the datacontext of the source item and enables LoadOnDemand for certain types.

    private void Treeview_LoadOnDemand(object sender, Telerik.Windows.RadRoutedEventArgs e)
          var radTreeViewItem = (RadTreeViewItem)e.OriginalSource;
          radTreeViewItem.IsExpanded = true;
          var childItems = GetChildItems(radTreeViewItem.DataContext);
          foreach(var child in childItems)
                var routeTreeViewItem = new RadTreeViewItem
                                                        DataContext = child,
                                                        Header =,
                                                        OptionType = OptionListType.None
          radTreeViewItem.IsLoadingOnDemand = false;
          radTreeViewItem.LoadOnDemand -= Treeview_LoadOnDemand;

    The resulting tree view displays a checkbox for every item in the tree, even though the child items have an OptionType of None.  If I set IsVirtualizing to false, the items are created correctly.  I would like to use the virtualizing feature though as we can have over 1000 items in our top layer and some of our clients are running very old machines.

  2. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 24 Sep 2012 Link to this post

    Hi Josh,

    I examined your code snippets and I noticed that you're populating the RadTreeView with RadTreeViewItems. However, when using the UIVirtualization feature of the control, it's important to note that it is designed to work within a databound RadTreeView. This means that it will only work correctly, if the RadTreeView.ItemsSource collection is populated with business items.

    I believe that this is causing your issue, and therefore I'd like to suggest a different approach for your scenario. As you have a collection of data items, you can directly use it as the RadTreeView.ItemsSource. This will leave the RadTreeViewItems generation process up to the RadTreeView and the virtualizaiton feature. Please have a look at our demo solution as it can get you started.

    Furthermore, the built-in CheckBox/RadioButtons support is designed to work with declaratively populated RadTreeView and if you databind the control, it would be better to create two separate DataTemplates for the items - one with a CheckBox and one with a RadioButton. This will allow you to use the ItemTemplateSelector to choose the ItemTemplate of each item based on your data type or properties. And you will also be able to control the check state of the items in your view models. For example in a MVVM scenario, we recommend using such an approach to create a 'tri-state' checking logic as described in this tutorial.

    Please try this approach instead and let us know if you still encounter any issues.

    Kind regards,
    Tina Stancheva
    the Telerik team

    Time to cast your vote for Telerik! Tell DevPro Connections and Windows IT Pro why Telerik is your choice. Telerik is nominated in a total of 25 categories.

  3. Josh
    Josh avatar
    27 posts
    Member since:
    Feb 2012

    Posted 25 Sep 2012 Link to this post

    Thanks for your response Tina.

    Unfortunately because of how we are using the tree view here, I don't think we'll be able to easily implement your suggestions.  We've created a control that essentially contains the tree view, a search box, and a busy box.  We then have several other controls that inherit from this control with each one populating the tree slightly differently.  The next wrinkle is that these controls are then dynamically created at runtime based upon selections the user makes in previous screens.  Since we really only need virtualization for one implementation of this control, the effort to rewrite this functionality isn't worth the reward.  We've decided to just add another layer to the troublesome implementation and stick with the load-on-demand functionality.
Back to Top