通过TreeNode.Value == strId 找到TreeNode的节点

2017-11-07 09:20:33  访问(1714) 赞(0) 踩(0)



        /// <summary>
        /// 通过TreeNode.Value == strId 找到TreeNode的节点
        /// </summary>
        /// <param name="tnc"></param>
        /// <param name="strId"></param>
        /// <returns></returns>
        public TreeNode TreeNodeFind(TreeNodeCollection tnc, string strId)
        {
            if (tnc == null)
                return null;

            if (strId == null || strId.Length == 0)
                return null;

            TreeNode theResult = null;

            foreach (TreeNode tn in tnc)
            {
                if (tn.Value == strId)
                    return tn;

                theResult = TreeNodeFind(tn.ChildNodes, strId);

                if (theResult != null)
                    return theResult;
            }

            return null;
        }


      
        /// <summary>
        /// 通过TreeNode.Value == strId 找到TreeNode的节点
        /// </summary>
        /// <param name="tnc"></param>
        /// <param name="strId"></param>
        /// <param name="allSon">是否包括下级节点</param>
        /// <returns></returns>
        public TreeNode TreeNodeFind(TreeNodeCollection tnc, string strId,bool allSon)
        {
            if (tnc == null)
                return null;

            if (strId == null || strId.Length == 0)
                return null;

            if (allSon)
            {
                TreeNode theResult = null;


                foreach (TreeNode tn in tnc)
                {
                    if (tn.Value == strId)
                        return tn;


                    theResult = TreeNodeFind(tn.ChildNodes, strId);

                    if (theResult != null)
                        return theResult;
                }
            }
            else
            {               

                foreach (TreeNode tn in tnc)
                {
                    if (tn.Value == strId)
                        return tn;
                     
                }
            }

            return null;
        }


上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)