Checkboxes in RadTreeview

9 posts, 0 answers
  1. Chandu
    Chandu avatar
    23 posts
    Member since:
    Jul 2012

    Posted 28 Aug 2012 Link to this post

    Hello,

    I'm new in Telerik, and I have spent a very long time trying to solve a problem concerning the checkboxes state in a RadTreeview. 
    I'm using Hierarchical Data Template  in my RadTreeview and adding Items into Treeview dynamically from the database 

    my problem is am able to select multiple checkboxes, in my case when i check a checkbox in parent or child or sub child the other should be get unchecked automatically....

    Please help me regarding this

    Thank you 
  2. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 28 Aug 2012 Link to this post

    Hi Chandu,

     Please check out these help articles which will help you proceed further:
    How To Create Tri State CheckBoxes in MVVM Scenarios
    Declarative Scenarios: CheckBox Support - TriState CheckBoxes

    All the best,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Chandu
    Chandu avatar
    23 posts
    Member since:
    Jul 2012

    Posted 29 Aug 2012 Link to this post

    Hello Petar,

    I am not using Declarative scenario however
     Tri State CheckBoxes in MVVM Scenarios 
    is given me good knowledge. In my case i no need of tri-state checkbox to maintain.

    Am using WCF Service to bind treeview, all i need to do is when i check a checkbox in parent or child or sub child the other should be get unchecked automatically.... 

    Please help me regarding this.

    Thank you
  5. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 29 Aug 2012 Link to this post

    Hi Chandu ,

     Can you please confirm that you need the following requirement: checking a random RadTreeViewItem will uncheck all other existing RadTreeViewitems in the tree?

    Greetings,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Chandu
    Chandu avatar
    23 posts
    Member since:
    Jul 2012

    Posted 29 Aug 2012 Link to this post


    yeah petar ,
    Exactly that is my requirement.

    The following i will explain my scenario clearly
     first i selected node2 check box

    node11
     -node2(selected check box)
     -node3
    node4
     -node5
     -node6

    Here again I selected node5

    node1
     -node2(selected check box)
     -node3
    node4
     -node5(selected check box)
     -node6 

    So automatically the first one(node2) should be unchecked.

     
  7. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 30 Aug 2012 Link to this post

    Hello Chandu,

     The straightforward solution is to use the Checked event of the RadTreeView, iterate over the whole tree and uncheck the checked item(s). However, this is not elegant. You mentioned that you use HierarchilDataTemplates and populate the tree from your DB. This allows you to introduce ViewModel wrapper classes to wrap your DB (business) objects and MainViewModel. Then you can create "CheckedItems" collection in the MainViewModel and synchronize it on every check/uncheck operation. 
    In the ViewModel wrappers you can have boolean property which is bound to the CheckState of the RadTreeViewItems via converters and StyleBindings (in WPF and SL5) or ContainerBindings in SL4.
    In this property's setter you can have something like: 

    set
    {
      if(value == false)
            this.parentMainViewModel.CheckedItems.Remove(this);
       else
             this.parentViewModel.CheckedItems.Clear();
            this.parentViewModel.CheckedItems.Add(this);
    }

    All the best,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  8. John
    John avatar
    8 posts
    Member since:
    Apr 2016

    Posted 21 Apr in reply to Petar Mladenov Link to this post

    I haven't found a post that already asks or answers my question, but this thread is darn close.

    I have implemented the tri-state MVVM logic from the How To article. While walking through some scenarios relating to the propagation of a node check activity, a question arose regarding the reentrancyCheck flag used in the IsChecked setter:

    set
    {
        if (isChecked != value)
        {
            if (reentrancyCheck)
                return;
            reentrancyCheck = true;
            isChecked = value;
            UpdateCheckState();
            OnPropertyChanged("IsChecked");
            reentrancyCheck = false;
        }
    }
    How would execution ever get to the test of reentrancyCheck when its value is true? I can understand that checking the node could cause the parent node to get checked which would then result in this node getting checked again, but wouldn't the test if (isChecked != value) result in skipping all the setter processing, including the test of the reentrancyCheck flag, since value will be the same as that assigned to isChecked immediately prior to calling UpdateCheckState?

  9. Petar Mladenov
    Admin
    Petar Mladenov avatar
    2891 posts

    Posted 25 Apr Link to this post

    Hello John,

    I use this application for testing purposes. You can expand the if and place breakpoint:
    if (reentrancyCheck)
                       {
                           return;
                       }
    Check and uncheck a node with children and the breakpoint will be hit. When unchecking with mouse the node will be first time unchecked via the built-in wpf mechanism ( you can clicking on checkbox), then re-entrancy is hit because when all children are unchecked , there is no need to uncheck their parent again.

    Regards,
    Petar Mladenov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  10. John
    John avatar
    8 posts
    Member since:
    Apr 2016

    Posted 29 Apr in reply to Petar Mladenov Link to this post

    Aha! Now I get it. When it propagates the state change to the first child, that causes reentrance to set the check state to null instead of the state that initiated the process.

    Thanks.

Back to Top
DevCraft banner