Checkbox behavior in RadTreeView control
I am using a Telerik RadTreeView control to build a tree with nodes containing checkboxes.
The default behavio开发者_Go百科r for this control is that if you check a parent node, all of the child nodes within it will also become checked. Is there any way to change this behavior? I want to be able to check a parent node on or off and not have it affect the children.
Thanks
I would try doing some magic when the PreviewChecked event happens. I'm not sure, but maybe you can use it to detect a checkbox is about to become checked, and prevent this from happening if it is not the checkbox the user actually clicked in.
You could also do some stuff in javascript like this
function checkNode()
{
var selectedNode = treeView.get_selectedNode();
if (!selectedNode)
{
alert("You need to select a node first.");
return false;
}
selectedNode.set_checked(!selectedNode.get_checked());
return false;
}
This is straight from telerik but simply loop through all the children nodes and turn them back off (or back on when you click it off). The problem is if you want to maintain the state of the children nodes regardless of the parent. Then you need to hold that info in some variable.
The other option is if you don;t want the children to even have checkboxes, then simply don;t make those nodes "Checkable" in the server side code. (I'm sure there is a way in the client side too)
精彩评论