The sample code runs as shown below:
In many cases, we often need to implement a tree's polymorphic selection, as shown in the figure above, when all child nodes are selected, the current node is selected (such as the diagram [Jingmen] node) and the current node is in a third state when the child node is partially selected (for example, the [Hubei Province] node) when all child nodes are not selected The current node is in an unchecked state (such as the diagram [Jiangsu Province] node). In this paper, we introduce the method of realizing the three-state selection tree.
In the VC Knowledge Base phase 19th, Henan University of Science and Technology Conre Friends also introduced a method of implementation, the two methods are compared, the method introduced in this article is simple, compatible with the original CTreeCtrl all operations, checkbox is also the control itself to use the checkbox, only in the state of the display when the redraw. Therefore, this method can display the icon of the node icon in the case of three states, and also increase the control of whether the checkbox is displayed at some nodes, while the control of selecting and canceling the keyboard space bar is increased. The method of traversing the parent and child nodes is similar to the method of Conre friend friend, and it is recursive to realize the traversal of all nodes, but it is optimized some more efficiently.
Here's how to use this:
Step one: Generate a dialog box Project (sample Engineering Cmutitree).
Step Two: Add the tree control and set the desired properties as needed.
Step three: Make the node icon and the three-State selection box icon
In general, the node icon using 16x16, three-state selection icon to use the 13x13 size is more appropriate.
Three-State selection icon corresponds to: 0-> No selection button 1-> did not select the 2-> part of the selection 3-> all selected
Step four: Add two files [MutiTreeCtrl.cpp, MutiTreeCtrl.h] to the dialog box created by step one