6. Graphic list Components TreeView
45) Q: Sometimes, I want to implement the display mode of the similar resource manager to the folder management, and what should I do in C Builder in the C Builder?
A: You can use graphic list components directly in C Builder, which includes TreeView, ListView, and Outline components. The OUTLINE components are actually based on the Windows 3.1 environment, and whether it is not possible with the TreeView, it can be used instead of the TreeView component compared to TreeView, regardless of the perspective of the function or use. So I will mainly introduce the two components in front. Both components are in page WIN32.
46) Q: What kind of component is the TREEVIEW component?
A: The TreeView component is more complicated, so we first briefly introduce the basic usage of this component, and then discuss it.
The TreeView component uses a tree structure, the most typical example is the resource manager of Windows 95, which displays the folders and files on the disk with a tree structure. Therefore, the TreeView component can clearly display hierarchical relationships.
47) Q: Please give me a demonstration how to edit TreeView in design status?
A: First place a TreeView component on the form, and then click the omitial button in the property items in the Object Editor to open a project editor.
TreeView Components The project editor is a tool that is specifically added, deleted nodes, and a node to the node. As can be seen from the screen, the project editor consists of the project group box and the project properties group box. The project group box consists of a project list box, buttons new item, buttons new subitem, buttons delete, and button LOAD. When you just open the project editor, the project list box is empty, the New SubItem and the Delete button are in the failure state.
The project attribute group box is composed of edit box text, edit box image index, edit box Selected Index, and edit box State Index.
The project group box can create and delete nodes, child nodes. If you want to load an existing TreeView node, you can click on the button LOAD. To create a new project, click New Item, and then enter the title of the new node in the Text Edit box. At this time, the New SubiteM button is valid by the failure, allowing you to nest the child node under the node. If the node is displayed in the project list box, the Delete button will also become effective. You can delete this node as long as you select this node in the project list box and then click the Delete button.
It should be noted that if the deleted node also includes a child node, the child node will be deleted simultaneously.
The project attribute group box is mainly to set the properties for the currently selected node (or child node). The edit box Text can modify the title of the node. If you want to display an image on the left side of the node currently selected, you should enter an index number of the image in the edit box image index. To disable the display image can set this node image index to the default value -1.
If the image is to be displayed on the left side of the selected node, the index number of the image should be specified in the edit box Selected Index, and the index number starts from 0. To disable the display image can set it to the default value -1.
If an image is displayed in the left side of the node, you can enter the index number of the image in the edit box state index. This index number represents the index of the image list represented by the StateImages property in the Tree View component. To disable the display image can set this item to default -1.
Note: Image Index and Selected INDEX are imagelist specified by images; and State Index is used by the ImageList specified in StateImages. 48) Q: TreeView's properties are too much, I want to ask me to know which main properties?
A: Items: This property contains all nodes in the TreeView component, which is TTREENODES object, when design, you can use the project editor to increase, delete, and modify nodes. During operation, each node can be accessed via the Items property, and the node can be increased, deleted and modified. Each node is a TTREENODE object.
AutoEWXPand: Boolean type. When TRUE, the currently selected node will be automatically extended, and no nodes will be folded automatically. The default is False, and the expansion and folding should be specified by the user.
DragMode: It declares: _Property TDRAGMODE DRAGMODE; this property is used to set the drag and drop mode of the tree view. The default is DMMANUAL, and users want to drag and drop nodes to call Begindrag to drag and drop. If set to DMAUTOMATIC, the tree view will support automatic drag and drop, and the user can drag a node to another.
Images: Used to set icons for different nodes in TreeView.
StateImages: Different images represent different status of nodes.
In the TreeView component, each node can be attached to an icon in addition to a text title, so that the user interface is more intuitive. These two attributes contain icons used by nodes.
Both attributes are TimageList objects, so if you want to add icons to the node in the TreeView component, you must assign these two attributes to these two attributes. If you place the icon list component in the form, click the drop-down button in the property images, you can choose this component.
When the showbuttons property value is TRUE, it means that the node with a child node will automatically have an extended button (ie "button) and the folding button (ie, the minus button), and click them to extend and fold the node. When the attribute value is false, these two buttons are not displayed, the default is true.
The showlines property is used to determine whether the connection between the node and the subtitle is displayed. The default is TRUE.
The Showroot property is used to determine if the top-level node is connected. The default is TRUE.
HideseEection property is used to determine if the selected node is in the selected state when the input focus moves from TreeView to other controls. When the property value is TRUE, it is no longer selected. The default is TRUE.
The Indent property is used to set the distance between the child node and the parent node.
Readonly is used to determine if the user can directly modify the title of the node. When the attribute value is false, it indicates that it can be modified. The modification method is to select the node you want to modify and click Go to the Edit Status. The default is false.
SortType is used to set the node to sort. It has the following values:
STNONE: No sorting (default);
StDATA: Reorder when the object associated with the node changes;
StTEXT: Reorder when the tag of the node changes;
StBoth: Reorder when the object or node's label is changed.
The above sorting principle is sorted in the alphabetical order of the same layer.
In addition, there are some running timelines.
TopItem: This property is used to set a node, which will display the top of the tree view. Rowselcet: The default is false. If set to True, the reach of the currently selected node will be highlighted. This property is invalid when Showlines is set to TRUE.
SELECTED: The node used to return it.
49) Q: What is the difference between attributes Images and StateImages?
A: Each node can have two attached icons. Under normal circumstances, only one icon needs to be displayed. At this time, we often use images to specify icons, which means to give an ImageList object to the property Images. If a node wants to display two icons, then you also need to give an ImageList object to the properties StateImages. Then give the node's attribute stateIndex specify the index number of the icon. The specific method is to modify the value of the edit box State Index in the project editor.
In fact, when displaying an icon, you can also use properties StateImages. However, there is an advantage that it can be used to specify different icons for nodes in different states. For example, in the resource manager of Windows 95, the selected node displays an open folder, without the selected node displays a closed folder. To achieve this is simple, because the edit box in the project editor Image Index specified by the icon is displayed when the node is not selected, and the image specified by the edit box Seleted Index is displayed when the node is selected.
50) Ask: On the basis of the TreeView component of the previously designed TreeView component, add icons to the TreeView components. Ok?
A: Ok, first place two imagelist components on the form, the two components will have the default name ImageList1 and ImageList2.
Second, edit the imagelist component: ImageList component is actually an icon list, which can contain a large number of icons, which are determined by attribute width and height, and the default value is 16.
ImageList does not include any icon when it is created, you need to introduce the created icon into ImageList. This job can be done through the ImageList editor.
Right-click ImageList components, select ImageList Editor or double-click this component in the shortcut menu, and then the following editor will appear.
Click the Add button, select the image file you want to introduce in the pop-up Add Images dialog box, the icon will appear in the images box. As can be seen from the figure, the introduced icon is automatically assigned to the index number.
For the convenience of use, each icon has a number, this number is the index number of this icon. If you want to reference an icon, you only need to use its index number.
It should be noted that this editor automatically breaks the introduced image into 16 × 16 icon, whose size is 16 × 16 because ImageList's attributes Width and Height are set to 16. If the size of the icon is different, then these two properties can be modified to meet the requirements of the icon.
Then, continue to add an icon to the node with the project editor: We have added two icons in the icon list component, and the index number is 0 and 1, then you can use the project editor to add icons to the node.
Open the project editor again and enter all nodes.
Modify the imageIndex, SELECTEDIDEX property of the node,
It should be noted that the index number in the edit box image index is 0, the index number in the edit box Selected Index is 1. That is to say, the icon displayed by the node is different in the selected or not selected.
Modify the icon index number of all nodes, so that there are two different icons containing the nodes of the child node, and only one icon of the nodes of the sub-node is the same, that is, the edit box image index and the SELECTED INDEX's index number. Finally, modify the ImageS property of the TreeView1 component, select ImageList1 components from the drop-down list.
As can be seen from the screen, the icon has appeared inside the control.
51) Q: How do you add the second icon to the node?
A: To add a second icon to the node, you must first create an icon list component, and then assign this icon list to the properties of the TreeView component StateImages. Of course, you have to introduce the icon to this icon.
After completing these work, we can enter the project editor. Select the node to add the second icon, modify the index number in the edit box State Index.
52) Q: What important functions are TreeView?
A: AlphaSort: It is: BOOL _FASTCALL AlphaSort (Void); this function is used to sort all nodes in alphabetical alphabetical order. Returns true if sorted successfully.
FullCollapse: It is declared as a void _fastcall fullcollapse (void); the function of this function is to fold all nodes until the top layer.
FullexPand: It is declared as Void _fastcall fullxpand (void); this function is to expand all nodes until the bottom is. If the showButtons property is TRUE, all " " will become "-".
GethitTestinfoat: It declares that this is THITTESTS _FASTCALL GETHITTESTINFOAT (INT X, INT Y); this function returns the location relationship between the specified point and the tree view. The location of this point is determined by the parameters x, y. THITTESTS is a collection that may contain the following elements:
HTABOVE: above the customer area of the tree view;
HTBELOW: below the customer area of the tree view;
HTNowhere: In the client area of the tree view but below the last node;
HTONITEM: On a tag or icon on a node;
HTONBUTTON: On the left side of a node;
HTONICON: On the icon of a node;
HTONDENT: On the narrow line of a node;
HTONLABEL: On a tag of a node;
HTONRIGHT: On the right of a node;
HTONSTATEICON: On the status icon of a node;
HTTOLEFT: On the right side of the customer area;
Httoright: The left side of the customer area.
GetNodeat: It declares that TTREENODE * _FASTCALL GETNODEAT (INT X, INT Y); this function is used to return the node where the specified point is located. Parameters x, y is the coordinates of this point. Returns NULL if this point is no node.