在treeview中进行关键字查找
,输入关键字,然后点击“下一个”或者“上一个”按钮进行查找,

解决方案 »

  1.   

    up ppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp
      

  2.   

    就是一个遍历吗,找到后break,然后下一个时,从当前节点继续遍历
      

  3.   

    递归算法
    给你一段“下一个”的代码,“上一个”你参考这个写
       private TreeNode m_currNode = null;
            private void btnFindNext_Click(object sender, EventArgs e)
            {
                if (treeView1.Nodes.Count > 0)
                {
                    if (m_currNode == null)
                        m_currNode = treeView1.Nodes[0];                m_currNode = findNext("关键字", m_currNode);
                    if (m_currNode != null)
                        treeView1.SelectedNode = m_currNode;
                }
            }
            private TreeNode findNext(string strKeyword, TreeNode fromNode)
            {
                if (fromNode.Nodes.Count > 0)
                {
                    foreach (TreeNode node in fromNode.Nodes)
                    {
                        if (node.Text == strKeyword)
                            return node;                    return findNext(strKeyword, node);
                    }
                }
                else
                {                if (fromNode.NextNode != null)
                    {
                        if (fromNode.NextNode.Text == strKeyword)
                            return fromNode.NextNode;                    return findNext(strKeyword, fromNode.NextNode);
                    }
                    else if (fromNode.Parent != null && fromNode.Parent.NextNode != null)
                    {
                        if (fromNode.Parent.NextNode.Text == strKeyword)
                            return fromNode.Parent.NextNode;                    return findNext(strKeyword, fromNode.Parent.NextNode);
                    }
                }                        return null;
            }
      

  4.   

    上一步,把上面代码的NextNode改成PreNode应该就可以,你试一下
      

  5.   

    就是一个遍历,找到后break,记录下当前节点,然后下一个时,从当前节点继续遍历
      

  6.   

    a
      b
      c
    j
      b
      c
    h
      b
      b
    你的代码,查找b只能找到第一个b
      

  7.   


    a
      b
      c
    j
      a
        b
      c
    h
      b
      b
      

  8.   

    可以用treview.nodes.find方法试试,注意,里面的第一个参数是node的name,你可以第归,找到后,将其checked属性设置为true
      

  9.   

    我自己写的,已经在项目里面用过了,不过不是一个一个查,是自动查找所有 checkbox被勾选的项。给你参考。ps:其中FunctionInfo是我项目中用到的类,绑定在节点的Tag上。
    //获取tvw_Function中所有选中的节点信息
    //没有树生成则返回null,树中无选中节点返回空IList
    private IList<FunctionInfo> GetCheckedNodes()
    {
    //检验tvw_Function是否有内容
    if (0 == tvw_Function.Nodes.Count)
    {
    IList<String> logLines = new List<String>();
    StackTrace st = new StackTrace(new StackFrame(true));
    StackFrame sf = st.GetFrame(0);
    logLines.Add(sf.GetFileName());
    logLines.Add(sf.GetMethod() + " | " + sf.GetFileLineNumber());
    logLines.Add("    : tvw_Function has no content!");
    Common.Common.WriteLog(logLines,false);
    return null;
    } IList<FunctionInfo> functionList = new List<FunctionInfo>();
    TreeNode tnRoot , tnCurrent , tnCurrentPar;
    tnRoot = tvw_Function.Nodes["root"];
    tnCurrentPar = tnRoot;
    tnCurrent = tnCurrentPar.FirstNode; //遍历tvw_Function获取被勾选的节点信息
    while (tnCurrent != null && tnCurrent != tnRoot)
    {
    while (tnCurrent != null)
    {
    //若当前节点被勾选,且当前节点为有效功能节点(tag不为空),则将tag代表的功能加入返回功能列表
    if ((true == tnCurrent.Checked) && (tnCurrent.Tag != null))
    functionList.Add((FunctionInfo) tnCurrent.Tag); if (tnCurrent.Nodes.Count > 0)
    {
    //移动到下一层节点
    tnCurrentPar = tnCurrent;
    tnCurrent = tnCurrent.FirstNode;
    }
    else if (tnCurrent != tnCurrentPar.LastNode)
    {
    //移动到本层下一个节点
    tnCurrent = tnCurrent.NextNode;
    }
    else
    break;
    } //逐层回溯父节点
    while (tnCurrent != tnRoot && tnCurrent == tnCurrentPar.LastNode)
    {
    tnCurrent = tnCurrentPar;
    tnCurrentPar = tnCurrentPar.Parent;
    } //回溯停止后移动到本层下一个节点
    if (tnCurrent != tnRoot)
    tnCurrent = tnCurrent.NextNode;
    } return functionList; }
      

  10.   

    a
      b
        n
      c
    j
      a
      b
      c
    h
      b
      b
    这样就不可以,查b
      

  11.   


    a
      b
         n
      c
    j
      a
      b
      c
    h
      b
      b
      

  12.   

    treeView1.Nodes.Find("关键字",true)[0].下一个(上一个)
      

  13.   

    不需要遍历整个树,TreeNode的Name属性其实就是关键字,创建TreeView的时候指定一下这个属性,然后就可以使用Nodes.Find方法搜索符合关键字的节点,得到的是一个TreeNode的数组,然后,遍历这个数组就可以了。