protected void PopulateNode(TreeNode aNode)
{
  this.Cursor = Cursors.WaitCursor;  // Set up the wait cursor 
  string strDir = BuildDirectory(aNode);  // Build the directory tree string from the tree node
  Directory Dir = new Directory(strDir);  // Use the Directory class to get the files and directory names in the directory
  int count = 0;// Get each directory name and add it as a directory folder tree node
 for (int i = 0; i < Dir.GetDirectories().Length; i++)    
  {
    TreeNode ChildNode = new TreeNode(Dir.GetDirectories()[i].Name, 1,0);
    aNode.Nodes.Add(i, ChildNode);
    count++;
  }// Get each file name and add it as a file tree node
  for (int i = 0; i < Dir.GetFiles(m_strFilter).Length; i++)
  {
   TreeNode ChildNode = new TreeNode(Dir.GetFiles(m_strFilter)[i].Name, 2,2);
   aNode.Nodes.Add(i+count, ChildNode);
  } aNode.Expand();  // 显示子结点
  this.Cursor = Cursors.Arrow;  //设
}

解决方案 »

  1.   

    protected string BuildDirectory(TreeNode aNode)
    {
     TreeNode theNode = aNode;
     string strDir = ""; 
    // Cycle through the node and all its parents to build the full path of the directory while (theNode != null)
     {
      if (theNode.Text[theNode.Text.Length - 1] != '\\')
      {
       strDir = "\\" + strDir;
      } strDir = theNode.Text + strDir;
     theNode = theNode.Parent;
    }return strDir;}
      

  2.   

    public void treeView1_AfterSelect (object sender, System.WinForms.TreeViewEventArgs e)

    // check to see if the selected node is already populated
     if (e.node.Nodes.Count > 0 || e.node.ImageIndex == 2)
     {
      return;
     }// The node is not  populated, so populate the selected node PopulateNode(e.node);
    }protected void button1_Click (object sender, System.EventArgs e)
    {
     label3.Text = dirTree1.Path;
     label4.Text = dirTree1.FileName;
    }
      

  3.   

    各位高手:
            我想当你们到这种地步的时候头已经大了吧!!!
    呵呵,我给你们说个好的方法,也有助你们学习,最新我校用个这软件开发出几个管理软件来供大家参观。
    IT高手网站 ——www.topit.tk
    豫信软件公司网站——www.zzyxsoft.com
    学校网站——www.haetc.com
    可以去论坛发贴或者发E-mail:
    [email protected]
      

  4.   

    哈哈,谢谢各位高手,请snof到下一个贴子接分