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

Checkboxes in RadTreeview

8 Answers 214 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Chandu
Top achievements
Rank 2
Chandu asked on 28 Aug 2012, 05:54 AM
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 

8 Answers, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 28 Aug 2012, 08:17 AM
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.

0
Chandu
Top achievements
Rank 2
answered on 29 Aug 2012, 08:47 AM
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
0
Petar Mladenov
Telerik team
answered on 29 Aug 2012, 11:34 AM
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.

0
Chandu
Top achievements
Rank 2
answered on 29 Aug 2012, 12:02 PM

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.

 
0
Petar Mladenov
Telerik team
answered on 30 Aug 2012, 07:06 AM
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.

0
John
Top achievements
Rank 1
answered on 21 Apr 2016, 04:48 PM

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?

0
Petar Mladenov
Telerik team
answered on 25 Apr 2016, 08:03 AM
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.
0
John
Top achievements
Rank 1
answered on 29 Apr 2016, 05:54 PM

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.

Tags
TreeView
Asked by
Chandu
Top achievements
Rank 2
Answers by
Petar Mladenov
Telerik team
Chandu
Top achievements
Rank 2
John
Top achievements
Rank 1
Share this question
or