读书人

TreeList 树形控件 兑现带三种状态的C

发布时间: 2012-12-19 14:13:14 作者: rapoo

TreeList 树形控件 实现带三种状态的CheckBox
private void treeList1_AfterCheckNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e) { SetCheckedChildNodes(e.Node, e.Node.CheckState); SetCheckedParentNodes(e.Node, e.Node.CheckState); } private void treeList1_BeforeCheckNode(object sender, DevExpress.XtraTreeList.CheckNodeEventArgs e) { e.State = (e.PrevState == CheckState.Checked ? CheckState.Unchecked : CheckState.Checked); } /// <summary> /// 设置子节点的状态 /// </summary> /// <param name="node"></param> /// <param name="check"></param> private void SetCheckedChildNodes(DevExpress.XtraTreeList.Nodes.TreeListNode node, CheckState check) { for (int i = 0; i < node.Nodes.Count; i++) { node.Nodes[i].CheckState = check; SetCheckedChildNodes(node.Nodes[i], check); } } /// <summary> /// 设置父节点的状态 /// </summary> /// <param name="node"></param> /// <param name="check"></param> private void SetCheckedParentNodes(DevExpress.XtraTreeList.Nodes.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); } }?

读书人网 >编程

热点推荐