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

关键代码:

       /// <summary>
        /// 向上递归,获取符合条件的父节点
        /// </summary>
        /// <param name="node">需要向上递归的节点</param>
        /// <param name="conditionHanlder">判断条件【委托】</param>
        /// <returns>符合条件的节点【TreeListNode】</returns>
        public static TreeListNode GetSelfParentNode(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 = GetSelfParentNode(_parentNode, conditionHanlder);
            }
            return _conditonNode;
        }

.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; }

代码使用:

            TreeListNode _node = e.Node;
            TreeListNode _condionParent = _node.GetSelfParentNode(n => n.GetNodeType() == NodeType.Cab);//获取类型为CAB类型的父节点
            Trace.WriteLine(_condionParent.GetName());

.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-12 02:03:45

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

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

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

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

关键代码: /// <summary> /// 节点互斥同步 /// 说明 /// eg: ///TreeListNode _node = e.Node; ///_node.SyncMutexNodeCheckState(_node.CheckState, n => n.GetNodeType() == NodeType.Cab); /// </summary> /// <param name="node">需要互斥同步的节点</para

[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]父子节点CheckState状态同步

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

DevExpress TreeList利用递归绑定数据

private void TreeListBind(DataTable dt, int p) { treeList1.Nodes.Clear(); if (dt.Rows.Count < 1) return; DataView dv = new DataView(dt); dv.RowFilter = "ParentFieldName=" + p; if (dv.Count < 1) return; TreeListNode Node = treeList1.AppendN

二叉树递归与非递归遍历,最近公共父节点算法

#include <iostream> #include <stack> using namespace std; #define MAX 100 //字符串最大长度 typedef struct Node //二叉树结点 { char data; Node *lchild,*rchild; } *Btree; void createBT(Btree &t); //先序构造二叉树 void preorder(Btree &t); //二叉树递归先序遍历 void i

递归删除符合条件的目录,文件, kotlin,java

package a import java.io.IOException import java.nio.file.* import java.nio.file.attribute.BasicFileAttributes fun main(args: Array<String>) { val path = Paths.get("F:\\杨旭升\\dev\\dev_java") remove_recursively(path, 0, { name -> name ==

自定义JS函数,获取CLASS属性符合条件的元素

function getElementsClass(classnames){ var classobj=new Array(); var classint=0;//定义数组的下标 var tags=document.getElementsByTagName("*");//获取所有元素 for(i=0;i<tags.length;i++){//筛选出所有class属性符合条件的元素 if(tags[i].className == classnames){ classobj[clas

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

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