好像没听说TreeView有这个功能

解决方案 »

  1.   

    try:private TreeNode GetNodeByPath(TreeNode root,string path){
     int index = path.IndexOf(this.TreeView1.FullPath);
     string s ;
     if(index != -1)
     {
      s = path.Substring(0,index);
      path = path.Substring(index + 1);
      foreach(TreeNode node in root.Nodes)
      if(node.Text == s)
        return GetNodeByPath(node,path);
     }
     else
      foreach(TreeNode node in root.Nodes)
        if(node.Text == path)
       return node;
      return null;//节点不存在
    }
    ps:为什么不用一个TreeNode来存放节点呢?
      

  2.   

    to:FileNewExit((呵呵)) 
    ps:为什么不用一个TreeNode来存放节点呢?
    这句话什么意思啊?你有更好的主意吗?
      

  3.   

    重绘前用viewstate保存,重绘时恢复
      

  4.   

    我的意思是:
    你知道了Country\Region\State节点(比如是node),你就用一个TreeNode来保存它呀
     
      TreeNode currentNode = node;以后,你就持有这个节点对象了.不知道我理解(你的意思)得对不对:(
      

  5.   

    刚好我做过的,给你代码直接能用
    public TreeNode FindNodeOnPath(TreeNodeCollection tn, string nodepath)
    {
    string str1 = null;
    string str2 = null;
    if(tn.Count < 1)
    return null;
    TreeNode TempTn = null;
    int pos = nodepath.IndexOf('\\' ,0 );
    if(pos > 0)
    {
    //当前要找的结点
    str1 = nodepath.Substring(0, pos);
    //下一级目录的结点
    str2 = nodepath.Substring(pos + 1); 
    }
    else
    str1 = nodepath;
    //从当前一级树目录中查找结点
    for(int i = 0; i < tn.Count; i++)
    {
    //找到了
    if(tn[i].Text == str1)
    {
    TempTn = tn[i];
    //是要找树结点的最终位置
    if(str2 == null)
    break;
    else
    {
    //继续往下查找
    TreeNode tnd = FindNodeOnPath(tn[i].Nodes, str2);
    if(tnd != null)
    TempTn = tnd;
    }
    break;
    }
    }
    //没找到返回空
    return TempTn;
    }
      

  6.   

    功能说明:
    参数是树根结点的结点集合,上次结点的fullpath实现了在树中定位到fullpath描述的结点,并返回这个结点,如果没找到则
    返回找到的它的父结点,什么没找到则为空。使用场合
    记录上次退出时用户最后一次点击的树结点,在一打开这个树时,就将当
    前结点定位到它上面,并展开树。