您的位置:首页 > 其它

Dev 11.2.5中关于选择TreeList控件自动选择

2011-12-26 16:03 495 查看
private void treeList1_AfterCheckNode(object sender, NodeEventArgs e) {
SetCheckedChildNodes(e.Node, e.Node.CheckState);
SetCheckedParentNodes(e.Node, e.Node.CheckState);
}
private void treeList1_BeforeCheckNode(object sender, CheckNodeEventArgs e) {
e.State = (e.PrevState == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked);
}
private void SetCheckedChildNodes(TreeListNode node, CheckState check) {
for(int i = 0; i < node.Nodes.Count; i++) {
node.Nodes[i].CheckState = check;
SetCheckedChildNodes(node.Nodes[i], check);
}
}
private void SetCheckedParentNodes(TreeListNode node, CheckState check) {
if(node.ParentNode != null) {
bool b = false;
CheckState state;
for(int i = 0; i < node.ParentNode.Nodes.Count; i++) {
state = (CheckState)node.ParentNode.Nodes[i].CheckState;
if(!check.Equals(state)) {
b = !b;
break;
}
}
node.ParentNode.CheckState = b ? CheckState.Indeterminate : check;
SetCheckedParentNodes(node.ParentNode, check);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: