Delphi Treeview usage

Then fine study today at Treeview usage, although online summed up a lot, but there are still many nodes are not talked about, also encountered a lot of problems to use. Specially summarize:

 

1, the concept of

Treeview for displaying data organized in a tree structure. Treeview control a tree by a node (the TreeNode) and the connecting lines. TtreeNode is the basic unit of TTreeview. And a node of the tree contains a text (Text) and data (Data). Text type is a String, Data was amorphous pointer (Untyped Pointer), can point to a data structure associated with the node. Each node of the lower sub-node formed Items property node, the current node has a unique Index (Index property of the TreeNode), for explaining the position of the sub node in the Items, each of the sub-nodes under the node is sequentially numbered, The first one is 0, the second 1, and so on. Obtained by the order of the child nodes IndexOf method, the absolute order (AbsoluteIndex) refers to the order starting with the first item value Treeview, the first is 0, thus pushed down. The property values ​​of the Item Index Index Returns the first child of the current node. Count the number of all child nodes belonging to this entry indicates. Item MoveTo method using shifted from one place to another.   
 
2, property   
 Expanded attribute indicates whether all children are fully expanded (including Child Child's), True to represent all unfold.   
 IsVisible property indicates whether an item can be seen in the tree, if the tree Expand Item is yes then this can be seen.    
 HasChildren attribute indicates whether an item has children. GetFirstChild, GetLastChild, GetPrevChild, GetNextChild return the first child of the current item, the last one before and one after a term.   
 GetNextSibling and GetPrevSibling next and previous item in the same Level is returned.   
 GetNextVisible and GetPrevVisible next and previous item can see is returned. If a node has a Parent, the HasAsParent method returns True. Parent is the parent of the current item. Focused property determines whether the focus falls on this node will be surrounded by a box when the standard Focus. Obviously, only one node will be focused.     
 Selected property indicates whether a node is selected, the same only one node will be selected.    
 DropTarget attribute indicates that the node is a source or target in the drag operation.   
    
3, add, delete, modify nodes:   
   Items can be static methods in the design editor is provided for each content node. Before adding and removing nodes must ensure that there is selected (Treeview.Selected = nil) to add a root node AddFirst, AddChild, etc., and on this basis, add a child node of this.   
  Treeview1.Items.AddFirst (nil, 'Root'); // add the first node has no parent root note (TTreeNode.Parent = nil)   
  Treeview1.Items.AddChild (nil, 'qt'); // add the first child node
  Remove node Treeview1.Selected.Delete {}
  Editing of the node content Treeview1.Selected.EditText {}
 
  Can be used when large quantities of data is added to the Treeview   
  TreeView.Items.BeginUpdate;   
  TreeView.Items.EndUpdate      
    
 4, the image displayed on the node   
  Treeview Several related image attributes:   
  SelectedIndex: When a node is selected what images selected in TimageList   
  OverlayIndex: FIG selected mask image as an askew (a transparent picture display of an image in front of the other),   
  X such as adding an image when a node is not available in front.   
  ImageIndex: number selected in the normal state of FIG.   
  StateIndex: StateImages in this ImageList corresponding sequence number, the display image is not -1, typical, like the file manager in the same display, the Treeview control image may be displayed before the node. Placed in the Form of a ImageList control, add a few pictures, respectively Index 0, 1, ... fill in the name of the control that you added in the Treeview ImageList Image property items.
When (Selected = nil) of the ImageIndex TreeNode node representing unselected picture number, SelectedIndex represent node numbers are selected picture.
E.g:

  TreeView1.Items[0].ImageIndex := 1;
  TreeView1.Items[0].SelectedIndex := 2;

    
3、TreeView的Level   
  I.e. hierarchical tree structure, such as: TreeView1.Selected.Level = 0; // first layer
 
4, expand and merge
  TreeView1.FullExpand; {} Expand
  TreeView1.FullCollapse; {} All combined
 
Finishing first, and then add back
Last updated on 2019.12.16
From: https: //www.cnblogs.com/guorongtao/p/12049414.html
 
 

 

Guess you like

Origin www.cnblogs.com/guorongtao/p/12049414.html