/// <summary> /// 清除所有勾选节点 /// </summary> public virtual void ClearAllCheckBoxSelectedNode() { NodesList.BeginUpdate(); foreach (var node in NodesList) { if (node.Node != null && node.Node.Item != null) { (node.Node.Item as UCheckBoxTreeViewItem).IsCheckBoxOn = false; } if (node.Node.Nodes != null && node.Node.Nodes.Count > 0) { for (int i = 0; i < node.Node.Nodes.Count; ++i) { (node.Node.Nodes[i].Item as UCheckBoxTreeViewItem).IsCheckBoxOn = false; } } } NodesList.EndUpdate(); }
/// <summary> /// 处理节点逻辑上的勾选 /// </summary> /// <param name="_nIndex"></param> /// <param name="_bCheck"></param> protected virtual void NodeCBValueChange(int _nIndex, bool _bCheck) { //当前开关按钮的节点 var node = NodesList[_nIndex]; NodesList.BeginUpdate(); //数据上改变 (node.Node.Item as UCheckBoxTreeViewItem).IsCheckBoxOn = _bCheck; //选择父节点时把子节点都选上 //if(node.Node.Nodes != null && node.Node.Nodes.Count > 0) //{ // for (int i = 0; i < node.Node.Nodes.Count; ++i) // { // (node.Node.Nodes[i].Item as UCheckBoxTreeViewItem).IsCheckBoxOn = _bCheck; // } //} //修改父节点的勾选状态 if (node.Node.Parent != null && node.Node.Parent.Item != null) { bool _bParentCheck = _bCheck; { if (_bCheck == false) { for (int i = 0; i < node.Node.Parent.Nodes.Count; ++i) { if (node.Node.Parent.Nodes[i].Item.IsCheckBoxOn == true) { _bParentCheck = true; break; } } } node.Node.Parent.Item.IsCheckBoxOn = _bParentCheck; } } NodesList.EndUpdate(); }