C#winform TreeView Simple Folder manager view files under Folders, files under sub-files

Source: Internet
Author: User

1 Viewing the contents of a folder

2 UI

3 Code

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.ComponentModel;4 usingSystem.Data;5 usingSystem.Drawing;6 usingSystem.IO;7 usingSystem.Linq;8 usingSystem.Text;9 usingSystem.Threading.Tasks;Ten usingSystem.Windows.Forms; One  A namespaceWindowsFormsApplication2 - { -      Public Partial classForm1:form the     { -          PublicForm1 () -         { - InitializeComponent (); +         } -  +         Private voidForm1_Load (Objectsender, EventArgs e) A         { at             stringPath =@"l:\ folders created with programs"; -  -             //The recursion of the function is used. - showeveryfile (path, treeview1.nodes);  -         } -  in         Private voidShoweveryfile (stringpath, treenodecollection nodes) -         { to             //dires Storage is the absolute path to the folder +             string[] Dires =directory.getdirectories (path); -              for(inti =0; I < Dires. Length; i++) the             { *                                        //the name of the folder $                 varnewnodes=nodes. ADD (Path.getfilename (dires[i));Panax Notoginseng                 //recursion of the function, appeared - Showeveryfile (Dires[i], newnodes.nodes); the             } +  A             //when a function is applied to the deepest depths, it is called when it is ready to come out one layer at a time . the             string[] files =directory.getfiles (path); +              for(inti =0; I < files. Length; i++) -             { $ nodes. ADD (Path.getfilename (files[i)); $             } -         } -     } the}

4 effects

See how the Iteration function works

1. Set a breakpoint on the line of code that calls the function that needs to be iterated
2, F5 run to the breakpoint
3, F11 a line of code, a row of the run.
4, observe the local Variables window and record the relevant parameters.

The iterative function is one layer deep, deep into the innermost layer, and then outward.

C#winform TreeView Simple Folder manager view files under Folders, files under sub-files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.