TreeView如何收缩所有节点,是在web应用程序

解决方案 »

  1.   

    遍历整棵树,设置每个节点SetAttribute("expanded","false")
      

  2.   

    ExpandAll方法的名字空间是什么?
    属于哪个类?
      

  3.   

    就是不想遍历才问问有什么别的好方法呀,可是看到的都是windows程序下的,郁闷
      

  4.   

    using System;
    using System.Drawing;
    using Microsoft.Web.UI.WebControls;namespace RunTimeWebControls
    {
    /// <summary>
    /// Summary description for WebTreeView.
    /// </summary>
    [ToolboxBitmap(typeof(System.Windows.Forms.TreeView))]
    public class WebTreeView:TreeView //TreeWeb
    {
    public WebTreeView()
    {
    this.SystemImagesPath = "/webctrl_client/1_0/treeimages/";
    this.AutoPostBack = true;
    this.AutoSelect = true;
    this.ShowLines=true;
    this.ShowPlus = true;
    this.BorderWidth=2;
    this.BorderStyle = System.Web.UI.WebControls.BorderStyle.Inset;
    }

    public void ExpandAll()
    {
    foreach (TreeNode loNode in this.Nodes)
    {
    ExpandChild(loNode);
    }
    } public TreeNode GetSelectedNode()
    {
    return this.GetNodeFromIndex(this.SelectedNodeIndex);
    } public static void ExpandChild(TreeNode poNode)
    {
    if (poNode!=null&&poNode.Nodes.Count>0)
    {
    poNode.Expanded = true;
    foreach (TreeNode loNode in poNode.Nodes)
    ExpandChild(loNode);
    }
    }
    }
    }=====================我写的是全部打开的,你把 poNode.Expanded = false;就是你需要的了
      

  5.   

    cs:
    for (int i = 0; i < TreeViewMenu.Nodes.Count; i++)
    {
        TreeViewMenu.Nodes[i].Expanded = false;
    }