CheckedItems is Empty

2 posts, 0 answers
    WILLIAM avatar
    134 posts
    Member since:
    Jun 2012

    Posted 08 Oct 2012 Link to this post

    I'm having some trouble with the CheckedItems list.  I'm creating and setting my ItemsSource which is a list of RadTreeViewItems.  For certain nodes, I'm setting the IsChecked and IsExpanded properties.  However when the control is displayed in the view, both of these properties are ignored.  The nodes where IsExpanded is set to true are not expanded.  When I expand them in the control, the Item that I set IsChecked is true IS actually checked.  But the CheckedItems list is empty.  I tried to programmatically add the item to the list before the control renders, but the the list is readonly.  So my question is: If I can't do it programmatically, what has to happen in order for the items that are checked to show up in the checked items list?  The majority of the time, our users will only look at the tree and use options that have been checked by default.  i.e. our business case is, the view opens, it's checked nodes should show as checked, it's parent(s) should be expanded, and they click a button to submit the checked items in the tree.  But it seems like you are requiring some sort of explicit interaction between the tree the and user.

    I'm also finding some other weird behavior.  When the tree is displayed and only the root nodes are visible; I can check one of those nodes and it appears that all of it's children are checked as well, which is the expected behavior; but again, the CheckedItems collection is empty.  What is this property used for and how do I make it work that if an item is checked, it is in this collection?
    Thanks for your help!!

  2. Tina Stancheva
    Tina Stancheva avatar
    3299 posts

    Posted 11 Oct 2012 Link to this post

    Hello William,

    The RadTreeView.ItemsSource collection should contain business items as its purpose is to populate the control with data items. Basically when you use the ItemsSource property you need to keep in mind that the RadTreeView will create a RadTreeViewItem container for each item in the ItemsSource collection. This is related to the fact that the control treats this collection as filled with business data.

    So in your case, as you're creating an ItemsSource which is a collection of RadTreeViewItems, you'll get for each item in the control a RadTreeViewItem wrapped in another RadTreeViewItem. And both will have expanded and check states so this is probably the cause for your issues.

    This is why I'd advice you to populate the RadTreeView with business items as described here. And in order to implement a custom checking logic, it's best to follow this tutorial. As for the expanding logic, you can also control it through a business property if you bind the IsExpanded property of each RadTreeViewItem container to a business value as demonstrated here.

    Pleas try the listed suggestions and let us know if they help or if you're still experiencing issues.

    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top