其他分享
首页 > 其他分享> > TreeList节点展开与收缩

TreeList节点展开与收缩

作者:互联网

介于树节点的展开与收缩是经常多处使用的,这里就写个两个调用方法。

        /// <summary>
        /// 展开指定节点以及其父节点
        /// </summary>
        /// <param name="tree">树</param>
        /// <param name="appointNode">要展开的节点</param>
        public static void ExpandAppointTreeNode(this TreeList tree, TreeListNode appointNode)
        {
            tree.Nodes.TreeList.FindNodeByID(appointNode.Id).Expanded = true;
            while (appointNode.ParentNode != null)
            {
                tree.Nodes.TreeList.FindNodeByID(appointNode.ParentNode.Id).Expanded = true;
                appointNode = appointNode.ParentNode;
            }
        }
        /// <summary>
        /// 收缩指定节点
        /// </summary>
        /// <param name="tree">树</param>
        /// <param name="appointNode">要收缩的节点</param>
        public static void ShrinkAppointTreeNode(this TreeList tree, TreeListNode appointNode)
        {
            tree.Nodes.TreeList.FindNodeByID(appointNode.Id).Expanded = false;
        }
View Code

 

标签:收缩,tree,ParentNode,appointNode,FindNodeByID,TreeList,节点
来源: https://www.cnblogs.com/smallwater/p/11748677.html