Propagation of CheckState towards the root on programmatic CheckState change

3 posts, 0 answers
  1. Domagoj
    Domagoj avatar
    17 posts
    Member since:
    Jun 2011

    Posted 29 Sep 2011 Link to this post

    I have a RadTreeView with some items (see the picture).
    The tree is set up to TriState with Checkboxes.

    When I programatically set the CheckState property of a leaf node to ToggleState.On, it does not automatically set its parents' CheckState to either Indeterminate or On (depending on whether all the children are checked), for some of the nodes. If you take a look at the attached picture, the selected nodes were XW16351, XW2 and XW3. However, only the XW3 node's parent was checked accordingly.

    If I now manually click the node (XW2 for example) with the mouse, the item gets unchecked. When I click it again to check it, all its ancestors get appropriate state (Indeterminate in my case), which is how it should work. But it does not work if the CheckState was made programatically. (I do not change the state at any other place in code and there are no bindings on that property).

    Is this a bug or a feature? :) Shouldn't automatic checking of ancestors in TriState-mode work even if the node was checked programatically, and not by the mouse click?

    Is there any simple workaround?

    Even more interesting scenario:
    - I programmatically set the node's CheckState property to ToggleState.On. (this will check only the node, not its ancestors)
    - I mouse-click the node to uncheck it. (which works as intended)
    - I mouse-click the node again to check it. (now the node is checked and ancestor nodes indeed get to Indeterminate state)
    - I mouse-click the node again to uncheck it. (the node and its ancestors get unchecked)
    - I programmatically set the node's CheckState proerty to ToggleState.On. (unlike the first step, this works as it's supposed to - the node gets checked and its ancestors get to Indeterminate state).

    How is this possible? Why does the programamtically setting the CheckState doesn't work the first time, but works correctly after some mouse-clicking intervention?

    One more thing I managed to deduce from my testing is that if I have previously expanded (manually) the nodes that I wish to check, so the nodes were already shown - then programmatically setting the CheckState works as intended. Which should explain why things work as described in my previous edit. Virtualization is turned off for this tree.

    Why do the elements of the tree need to be shown before such behavior starts working?
  2. Mike
    Mike avatar
    10 posts
    Member since:
    Jun 2011

    Posted 03 Oct 2011 Link to this post

    I am having the exact same problem.  I also noticed that if I set a parent node programmatically, that has never been expanded, it does not propagate to it's children.  However, if I expand, and then collapse the parent node, then set it programatically, it works.  I assume something isn't loaded until the node is shown the first time, is it possible to force the load to take place so that I can use this behavior?
  3. Petar Mladenov
    Petar Mladenov avatar
    3162 posts

    Posted 04 Oct 2011 Link to this post

    Hello Mike and Domagoj,

     This behavior is expected by design. The RadTreeViewItems are the visual containers of your data which you wish to show. Initially, after the RadTreeView loads, only the first (root-level) level RadTreeViewItems are generated. Then the child RadTreeViewItems are generated when their parent item gets expanded. Setting the CheckState or IsChecked before the RadTreeViewItem has been generated cannot activate the TriState logic automatically.
     The best way to achieve the desired functionality is to work with ViewModels and ContainerBindings. However, you have to keep in mind that the ContainerBindings have bigger priority than the default TriState behavior and I suggest you to implement it on your own so that it will work in every scenario. You can examine a TriState logic implemented in ViewModels in this code library project.
    Please let us know if you need further assistance on this.

    Kind regards,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top