当前位置:编程学习 > C#/ASP.NET >>

aspx treenode 递归遍历当前节点找下一个节点的错误,找到就停

 private void pastNode(TreeNode currentNode)
        {
            TreeNode tn = TreeView1.SelectedNode;
            TreeNode ftn = TreeView1.SelectedNode.Parent;
            int index = ftn.ChildNodes.IndexOf(tn);

            if (currentNode.ChildNodes.Count > 0)
            {
                foreach (TreeNode node in currentNode.ChildNodes)
                {
                    pastNode(node);
                }
            }
            else
            {
                if (getText(currentNode.Value,3)=="0")
                {
                    currentNode.Selected = true;
                    currentNode.Select();
                    return;
                    
                }else
                {
                    if (index + 1 >= 0)
                    {

                        foreach (TreeNode node in currentNode.Parent.ChildNodes[index + 1].Parent.ChildNodes)
                        {
                            pastNode(node);
                        }
                    }
                    
                }
            }
        }
大神们,看看哪错了。。找到错误循环不停止。。  --------------------编程问答-------------------- private bool pastNode(TreeNode currentNode)
        {
            TreeNode tn = TreeView1.SelectedNode;
            TreeNode ftn = TreeView1.SelectedNode.Parent;
            int index = ftn.ChildNodes.IndexOf(tn);

            if (currentNode.ChildNodes.Count > 0)
            {
                foreach (TreeNode node in currentNode.ChildNodes)
                {
                    if(pastNode(node)) return;
                }
            }
            else
            {
                if (getText(currentNode.Value,3)=="0")
                {
                    currentNode.Selected = true;
                    currentNode.Select();
                    return;
                    
                }else
                {
                    if (index + 1 >= 0)
                    {

                        foreach (TreeNode node in currentNode.Parent.ChildNodes[index + 1].Parent.ChildNodes)
                        {
                            if(pastNode(node)) return;
                        }
                    }
                    
                }
            }
        } --------------------编程问答-------------------- 少写两个地方
private bool pastNode(TreeNode currentNode)
        {
            TreeNode tn = TreeView1.SelectedNode;
            TreeNode ftn = TreeView1.SelectedNode.Parent;
            int index = ftn.ChildNodes.IndexOf(tn);

            if (currentNode.ChildNodes.Count > 0)
            {
                foreach (TreeNode node in currentNode.ChildNodes)
                {
                    if(pastNode(node)) return;
                }
            }
            else
            {
                if (getText(currentNode.Value,3)=="0")
                {
                    currentNode.Selected = true;
                    currentNode.Select();
                    return true;
                    
                }else
                {
                    if (index + 1 >= 0)
                    {

                        foreach (TreeNode node in currentNode.Parent.ChildNodes[index + 1].Parent.ChildNodes)
                        {
                            if(pastNode(node)) return;
                        }
                    }
                    
                }
            }
return false;
        } --------------------编程问答--------------------
引用 2 楼 aley 的回复:
少写两个地方
private bool pastNode(TreeNode currentNode)
        {
            TreeNode tn = TreeView1.SelectedNode;
            TreeNode ftn = TreeView1.SelectedNode.Parent;
            int index = ft……




+1
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,