Tree control (CTreeCtrl) class that supports data item lookup

Source: Internet
Author: User

The code-run effect is shown below:

First, the tree controls (Ctree control)

Tree control is used to display data items that have a certain hierarchy. Many applications use the control, such as the disk directory in the Explorer.

The tree control has a root data item (root item) that contains each child item under the root data item. The root data item is the father of all the child data items that are children of the root data item. All child data items are sibling (sibling) relationships. Each data item includes a data item name (a text string) and an image to represent the data item, which can also contain children under each data item, and the entire structure is like a tree.

Second, the use of tree control

In MFC, tree controls are encapsulated into CTreeCtrl classes. Let's talk about the creation, attributes, and manipulation of tree controls.

(1) Tree control creation

Tree control is generally used in dialog box programs. There are two ways to create a tree control, one is to create it statically, and one is to create it dynamically. Static creation is a member variable that is declared associated with a drag-and-drop control to manipulate tree control. Drag and drop a CTreeCtrl control on the dialog box program interface, and then add a member variable of the CTreeCtrl type by ClassWizard and use it in your program. Dynamic creation refers to creating a tree control object using the CREATE function in a program. This article uses the method of static creation.

(2) tree-controlled properties

Tree control has many property manipulation functions. You can use these functions to get the various attribute information that the tree controls. For example, obtains the number of items in the tree control GetCount, obtains the tree control the item relative to the parent item offset value GetIndent, obtains the tree control image List control handle getimagelist and so on. You can view MSDN help with specific information.

(3) control of the number of operations

Tree-controlled action methods include inserting a tree item insertitem, deleting a tree item deleteitem, deleting

All tree items Deleteallitems, expand, or close the child expand of the tree item, and select a specific tree item

SelectItem, select a tree item as the first visual tree item selectsetfirstvisible, edit a can

Depending on the tree item Editlabel and sort the subtree item SortChildren for the given parent tree item.

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.