可能只能用剃龟吧^_^
没属性能查询node的所有节点数

解决方案 »

  1.   

    楼主是想得到所有TREEVIEW的节点还是想得到一个节点的子节点,如果是要得到所有结点,需要遍历TREEVIEW,如果只想得到某个节点的子结点,可以用TreeNode.GetNodeCount得到节点数
      

  2.   

    Node.Nodes.Count只能得到当前节点的子节点数目,要得到一个节点下的所有子节点,
    需要使用递归算法遍历
      

  3.   

    真是晕呀,
    如果这样,那就比DELPHI和VB中的树麻烦多了,
      

  4.   

    private bool Search(TreeNode rtNode,string txt)
            {    
                bool ret=false;            if (rtNode.Nodes.Count!=0)
                { 
                    foreach(TreeNode node in rtNode.Nodes)
                    {
                        if(node.Text.ToUpper()==txt)
                        {
                            tvwDataSource.SelectedNode=node;
                            ret=true;
                            break;
                        }
                        else
                        {
                            ret=Search(node,txt);
                            if (ret)
                            {
                                break;
                            }
                        }
                    }
                } 
                return ret;
            }这就是所谓的第归方法
      

  5.   

    Node.Nodes.Count只能得到当前节点的数目,如果想要得到全部,得用递归
      

  6.   

    用 heiguangbao(大头) 的不好,容易造成死循环。
    用我的吧。
    public static int Search(TreeView tv)
    {
        if (tv.Nodes.Count <= 0) return null;
        TreeNode node = tv.Nodes[0];
        TreeNode ParentNode = node;
        int items = 1;

        while (node != null)
        {         if (node.Nodes.Count > 0) //有子节点
    {
    ParentNode = node;
    node = node.Nodes[0];
    }
    else                     //没有子节点
    {
    node = node.NextNode;
    while ((node == null) && (ParentNode != null))
    {
    node = ParentNode.NextNode;
    ParentNode = ParentNode.Parent;
    }
        }
    items++;
    } return items;
    }
      

  7.   

    这个方法试试:private void button3_Click(object sender, System.EventArgs e)
    {
    count = 0;
    NodeCount(this.treeView1.Nodes);
    MessageBox.Show(count.ToString());
    }
    int count ;
    private void NodeCount(TreeNodeCollection tnd)
    {
    foreach ( TreeNode tn in tnd )
    {
    count += 1;
    if ( tn.Nodes.Count != 0 )
    {
    NodeCount(tn.Nodes);
    }
    }
    }
      

  8.   

    TreeView.GetNodeCount( true );