/// <summary>
/// 选择某一节点时,该节点的子节点全部选择 取消某一节点时,该节点的子节点全部取消选择
/// </summary>
private void SetCheckedChildNodes(TreeListNode node, bool check)
{
if (node.ChildNodes.Count > 0)
{
for (int i = 0; i < node.ChildNodes.Count; i++)
{
node.ChildNodes[i].Selected = check;
SetCheckedChildNodes(node.ChildNodes[i], check);
}
}
}
/// <summary>
/// 某节点的子节点全部选择时,该节点选择 某节点的子节点未全部选择时,该节点不选择
/// </summary>
private void SetCheckedParentNodes(TreeListNode node, bool check)
{
if (node.ParentNode != null)
{
bool parentCheckState = node.ParentNode.Selected;
bool nodeCheckState;
for (int i = 0; i < node.ParentNode.ChildNodes.Count; i++)
{
nodeCheckState = node.ParentNode.ChildNodes[i].Selected;
if (!check.Equals(nodeCheckState))//只要任意一个与其选中状态不一样即父节点状态不全选
{
parentCheckState = !check;
break;
}
parentCheckState = check;//否则(该节点的兄弟节点选中状态都相同),则父节点选中状态为该节点的选中状态
}
node.ParentNode.Selected = parentCheckState;
SetCheckedParentNodes(node.ParentNode, check);//遍历上级节点
}
}
TreeList父子节点的选择
最新推荐文章于 2024-06-20 09:36:13 发布