天天看點

C# Winform TreeView 查找父節點

查找父節點

#region 查找父節點
        public TreeNode FindFatherNode(TreeNode SelectNode)
        {
            if(SelectNode != null)
            {
                if (SelectNode.Parent != null)
                {
                    TreeNode Fathernode = SelectNode.Parent;
                    if (Fathernode.Parent != null)
                    {
                         return  FindFatherNode(Fathernode);
                    }
                    else
                    {
                        return Fathernode;
                    }
                }
            }
            else
            {
                return SelectNode;
            }
           
            
            return SelectNode;
        }

        #endregion