[WinForm][DevExpress][TreeList]节点互斥

关键代码:

        /// <summary>
        /// 节点互斥同步
        /// 说明
        /// eg:
        ///TreeListNode _node = e.Node;
        ///_node.SyncMutexNodeCheckState(_node.CheckState, n => n.GetNodeType() == NodeType.Cab);
        /// </summary>
        /// <param name="node">需要互斥同步的节点</param>
        /// <param name="checkState">节点状态</param>
        /// <param name="checkHanlder">互斥条件【委托】</param>
        public static void SyncMutexNodeCheckState(this TreeListNode node, CheckState checkState, Predicate<TreeListNode> checkHanlder)
        {
            TreeList _tree = node.TreeList;
            if (checkHanlder(node))//当前节点符合互斥条件时候
            {
                _tree.DownRecursiveTree(n => n.CheckState = CheckState.Unchecked);
            }
            else
            {
                TreeListNode _curParentNode = node.GetParentNode(checkHanlder);//获取符合互斥条件的父节点
                if (_curParentNode == null) return;
                TreeListNode _thePubleNode = node.GetPublicParentNode(checkHanlder);//获取符合互斥条件的公共父节点
                if (_thePubleNode == null) return;
                foreach (TreeListNode n in _thePubleNode.Nodes)
                {
                    foreach (TreeListNode nc in n.Nodes)
                    {
                        if (nc != _curParentNode)
                        {
                            nc.CheckState = CheckState.Unchecked;
                            nc.DownRecursiveNode(nr => nr.CheckState = CheckState.Unchecked);
                        }
                    }
                }
            }
            node.SyncNodeCheckState(checkState);
            node.CheckState = checkState;
        }
    }
        /// <summary>
        /// 向上递归,获取符合条件的节点的公共父节点
        /// </summary>
        /// <param name="node">操作节点</param>
        /// <param name="checkHanlder">委托</param>
        /// <returns>符合条件的节点</returns>
        public static TreeListNode GetPublicParentNode(this TreeListNode node, Predicate<TreeListNode> checkHanlder)
        {
            TreeListNode _publicPNode = null;
            TreeListNode _findNode = node.GetParentNode(checkHanlder);//先获取到条件判断的自身父节点
            if (_findNode != null)
            {
                //开始向上递归
                UpwardRecursiveNode(_findNode, n =>
                {
                    TreeListNode _curpublicNode = n.ParentNode;//获取当前向上递归的父节点
                    if (_curpublicNode != null)
                    {
                        if (_curpublicNode.Nodes.Count > 1)//若有多个子节点,则是公共父节点
                        {
                            _publicPNode = _curpublicNode;
                            return false;//跳出递归
                        }
                    }
                    return true;//继续递归
                });
            }
            return _publicPNode;
        }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

        /// <summary>
        /// 向上递归,获取符合条件的父节点
        /// </summary>
        /// <param name="node">需要向上递归的节点</param>
        /// <param name="conditionHanlder">判断条件【委托】</param>
        /// <returns>符合条件的节点【TreeListNode】</returns>
        public static TreeListNode GetParentNode(this TreeListNode node, Predicate<TreeListNode> conditionHanlder)
        {
            TreeListNode _parentNode = node.ParentNode;//获取上一级父节点
            TreeListNode _conditonNode = null;
            if (_parentNode != null)
            {
                if (conditionHanlder(_parentNode))//判断上一级父节点是否符合要求
                {
                    _conditonNode = _parentNode;
                }
                if (_conditonNode == null)//若没有找到符合要求的节点,递归继续
                    _conditonNode = GetParentNode(_parentNode, conditionHanlder);
            }
            return _conditonNode;
        }
SyncNodeCheckState代码参考:http://www.cnblogs.com/Yan-Zhiwei/p/3808089.html
说明:
如图,Test3和蒙自路Test2都是"cab"类型;
当调用代码如下:
            TreeListNode _node = e.Node;
            _node.SyncMutexNodeCheckState(_node.CheckState, n => n.GetNodeType() == NodeType.Cab);

实现的效果就是要么只能勾选“Test3”或者“蒙自路Test2”节点或者子节点,不同同时勾选,应该就是互斥的意思;也是这段代码想实现的效果,希望有所帮助。
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

[WinForm][DevExpress][TreeList]节点互斥

时间: 2024-12-13 09:21:38

[WinForm][DevExpress][TreeList]节点互斥的相关文章

[WinForm][DevExpress][TreeList]向上递归,获取公共父节点

最近项目开发中,需要获取到公共节点,如图: 譬如,当点击"Test103-2"节点,其类型是"灯"类型,那怎么获取到"中心区域"这个类型是"地域"的公共节点了?(不知道描述清楚木有哈) 核心代码: /// <summary> /// 向上递归,获取符合条件的父节点 /// </summary> /// <param name="node">需要向上递归的节点</pa

[WinForm][DevExpress][TreeList]父子节点CheckState状态同步

关键代码: /// <summary> ///同步父子节点勾选状态 ///说明 ///在AfterCheckNode事件中使用代码 ///eg:e.Node.SyncNodeCheckState(e.Node.CheckState); /// </summary> /// <param name="node">需要同步的节点</param> /// <param name="check">节点当前勾选状态&

[WinForm][DevExpress][TreeList]条件隐藏节点CheckBox

关键代码: /// <summary> /// 隐藏CheckBox /// 说明 /// 在CustomDrawNodeCheckBox事件中使用 /// eg: /// TreeList _curTree = (TreeList)sender; /// _curTree.HideCheckBox(n => n.GetNodeType() == NodeType.Area || n.GetNodeType() == NodeType.CabsGroupRoot, e); /// <

[WinForm][DevExpress][TreeList]向上递归,获取符合条件的父节点

关键代码: /// <summary> /// 向上递归,获取符合条件的父节点 /// </summary> /// <param name="node">需要向上递归的节点</param> /// <param name="conditionHanlder">判断条件[委托]</param> /// <returns>符合条件的节点[TreeListNode]</return

[WinForm][DevExpress]设置TreeList图片节点背景色

关键代码: /// <summary> /// 设置图片节点的背景色 /// 说明:在CustomDrawNodeImages事件中使用 /// </summary> /// <param name="tree">TreeList</param> /// <param name="e">CustomDrawNodeImagesEventArgs</param> /// <param nam

[WinForm][DevExpress]设置TreeListNode的背景色

关键代码: /// <summary> /// 设置节点背景色 /// 在NodeCellStyle事件中使用 /// </summary> /// <param name="tree">TreeList</param> /// <param name="e">GetCustomNodeCellStyleEventArgs</param> /// <param name="bui

DevExpress TreeList 那些事儿

1:TreeList绑定数据源 当我们给予TreeList 的 parentFieldName 和 KeyFieldName 两个属性之后 会自动的生成树结构. 1 var sql = @" SELECT * FROM TRAININGANDPROJECT"; 2 DataTable dt = SQLiteHelper.ExecuteTable(sql); 3 treeList1.DataSource = dt; // 将DataTable绑定到 TreeList中. 4 treeLi

如何让DevExpress TreeList的每个结点高亮显示?

概述:如何让DevExpress TreeList的每个节点高亮显示? 如何让DXperience TreeList的每个节点高亮显示? 效果如下: private void treeList1_CustomDrawNodeCell(object sender, DevExpress.XtraTreeList.CustomDrawNodeCellEventArgs e)        {             TreeList node = sender as TreeList;       

DevExpress TreeList使用教程之绑定多级树

DevExpress TreeList使用教程之绑定多级树 概述:TreeList控件可以同时显示树结构和其他数据列,即在一个列上建立父子关系展开或收缩,同时还可以显示其他列的内容.在TreeList中同时引入了 Node和 Columns概念, 第一列为树结构, 其余列为数据列, 任何列都可作为树结构列(即拖动到第一列)显示 TreeList控件可以同时显示树结构和其他数据列,即在一个列上建立父子关系展开或收缩,同时还可以显示其他列的内容. 在TreeList中同时引入了 Node和 Colu