我正在使用 Telerik RadTreeView 控件来构建一棵树,其节点包含复选框。
此控件的默认行为是,如果您选中父节点,则其中的所有子节点也将变为选中状态。有没有办法改变这种行为?我希望能够检查父节点的开启或关闭,而不是让它影响子节点。
谢谢
我正在使用 Telerik RadTreeView 控件来构建一棵树,其节点包含复选框。
此控件的默认行为是,如果您选中父节点,则其中的所有子节点也将变为选中状态。有没有办法改变这种行为?我希望能够检查父节点的开启或关闭,而不是让它影响子节点。
谢谢
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)