Treeview and listview showing hierarchical folder system

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fonix232
    New Member
    • Feb 2010
    • 3

    #1

    Treeview and listview showing hierarchical folder system

    Hi there!

    I would like to ask for some help.
    I'm making a little application what is a modding tool, so in the main window it has a treeview and a detailed list view to show files what can be modded. But I just can't get around this, as I would need the treeview show all folders located under a given folder hierarchically, and the listview to show files and folders from the currently selected folder in the treeview. After doing some google searches, I found nothing. Could someone help me?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    After doing some google searches, I found nothing
    Let Me Google That For You (LMGTFY): for all those people who find it more convenient to bother you with their question rather than search it for themselves.



    http://msdn.microsoft.com/en-us/libr...45(VS.80).aspx

    Comment

    • fonix232
      New Member
      • Feb 2010
      • 3

      #3
      Thanks for it, I found the MSDN way a bit too "hacky", so I used another code:

      Code:
      public void PopulateTree(string dir, TreeNode node)
              {
                  DirectoryInfo directory = new DirectoryInfo(dir);
                  foreach(DirectoryInfo d in directory.GetDirectories()) 
                  {
                      TreeNode t = new TreeNode(d.Name);
                      PopulateTree(d.FullName, t);
                      dirView.Nodes.Add(t);
                  }
              }
      Last edited by tlhintoq; Feb 27 '10, 10:35 PM. Reason: [CODE] ...Your code goes between code tags [/CODE]

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        TIP: When you are writing your question, there is a button on the tool bar that wraps the [code] tags around your copy/pasted code. It helps a bunch. Its the button with a '#' on it. More on tags. They're cool. Check'em out.

        Comment

        • tlhintoq
          Recognized Expert Specialist
          • Mar 2008
          • 3532

          #5
          Way too hacky? Looks like virtually the same recursive loop to me.


          Originally posted by MSDN
          Code:
          private void GetDirectories(DirectoryInfo[] subDirs, 
              TreeNode nodeToAddTo)
          {
              TreeNode aNode;
              DirectoryInfo[] subSubDirs;
              foreach (DirectoryInfo subDir in subDirs)
              {
                  aNode = new TreeNode(subDir.Name, 0, 0);
                  aNode.Tag = subDir;
                  aNode.ImageKey = "folder";
                  subSubDirs = subDir.GetDirectories();
                  if (subSubDirs.Length != 0)
                  {
                      GetDirectories(subSubDirs, aNode);
                  }
                  nodeToAddTo.Nodes.Add(aNode);
              }
          }

          Comment

          Working...