首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-12-19 
TreeList 树形控件 实现带三种状态的CheckBoxprivate void treeList1_AfterCheckNode(object sender, DevE

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); } }?

热点排行