Loads the structure of the specified directory into the TreeView

Source: Internet
Author: User
Tags root directory

The TreeView component is a tree-like List component that is extremely widely used in the authoring of applications. Such as: Resource Manager, Internet Express (FlashGet), Foxmail, etc., in which Windows Resource Manager is a typical example.

In C + + builder, it is easy to use the TreeView component, as long as you invoke the Add or Addchild method of the TreeView component to easily add a new node to the TreeView. To place a tree structure of a specified disk or directory in the TreeView component, you can use the method of traversing the tree to add all directories (including subdirectories) and files under the specified disk or directory to the TreeView.

Next, let's use the actual example to load the C-disk tree into the TreeView.

First, run Borland C + + Builder 5.0, add two button components, an edit component, a TreeView component, and a animate component to the form Form1. The Caption property of the component Button1 is then changed to "Mount TreeView1", the Caption property of the component Button2 is changed to "clear", and the Text property of the component Edit1 is changed to "C:\" to set the root directory of the default directory--c disk to traverse. Component Animate1 is used to display animations when traversing directories, where its Commonavi property is set to "Avifindcomputer", and you can also set it to other animations to display an animation that looks for a computer.

Press F12 to open the Code editing window, in "TForm1 *form1;" Statement below, add the following statement to define the custom function Browdir:

void __fastcall Browdir (ttreenodes * nodes,ansistring pathname,ttreenode * Num);

The Browdir function is a custom function that implements a recursive call to traverse a directory. It has three parameters, the first parameter transmits a node of the TreeView component to add new nodes, the second parameter is the path to the specified directory, and the third parameter transmits a node to indicate that a new node is to be added to that node.

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.