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
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
Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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
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.
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.
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
);
}
Petar Mladenov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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
;
}
}
I use this application for testing purposes. You can expand the if and place breakpoint:
if
(reentrancyCheck)
{
return
;
}
Regards,
Petar Mladenov
Telerik
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.