TTreeView学习(三)-- TTreeNode


TTreeNode

需要了解的属性:

AbsoluteIndex

property AbsoluteIndex: Integer;

Use AbsoluteIndex to determine absolute position of a node in a tree nodes object. The first tree node in a tree nodes object has an index of 0 and subsequent nodes are numbered sequentially. If a node has any children, its AbsoluteIndex is one less than the index of its first child.

Count

property Count: Integer;

Use Count to determine how many child nodes belong to a tree node. Count includes only immediate children, and not their descendants. Count can be useful when iterating through the children of a tree node.

Cut

property Cut: Boolean;

Use Cut to alter the appearance of the tree node when it is selected as part of a cut and paste operation.

Data

property Data: Pointer;

Use the Data property to associate data with a tree node. Data allows applications to quickly access information about the entity represented by the node.

Deleting

property Deleting: Boolean;

Deleting returns true if the node object is in the process of being deleted. Use Deleting to prevent infinite recursion in event handlers.

DropTarget

property DropTarget: Boolean;

Use DropTarget to indicate that the node is a drag and drop target. When DropTarget is true, the node is drawn in a style used to indicate a drag and drop target.

Note: Setting DropTarget to true does cause the node to automatically accept dragged objects when they are released. The application must still implement the drop behavior.

Expanded

property Expanded: Boolean;

When a tree node is expanded, the minus button is shown if the ShowButtons property of the tree view is true and child nodes are displayed. Set Expanded to true to display the children of a node. Set Expanded to false to collapse the node, hiding all of its descendants.

Focused

property Focused: Boolean;

Tree view nodes are not windowed controls and so can’t receive input focus. However, they can be edited by the user when the tree view control has focus. When Focused is true, the node is surrounded by a standard focus rectangle and the user can edit the label. Use Focused to determine if a particular node in a tree view can currently be edited by the user.

Handle

property Handle: HWND;

Use Handle to obtain the handle of the tree view that owns the node. This handle can be passed as a parameter to Windows API function calls that require a handle to the tree view.

HasChildren

property HasChildren: Boolean;

HasChildren is true if the node has subnodes, or false if the node has no subnodes. If ShowButtons of the tree view is true, and HasChildren is true, a plus (+) button will appear to the left of the node when it is collapsed, and a minus (-) button will appear when the node is expanded.

Note: If a node has no children, setting HasChildren to true will show a (+) plus button, but will not add any child nodes and the node cannot be expanded.

ImageIndex

property ImageIndex: TImageIndex;

Use the ImageIndex property with the Images property of the tree view to specify the image for the node in its normal state.

Index

property Index: Longint;

Use Index to determine the position of the node relative to its sibling nodes. The first child of the parent node has an Index value of 0, and subsequent children are indexed sequentially.

IsVisible

property IsVisible: Boolean;

A node is visible if it is on level 0 or if all its parents are expanded. IsVisible indicates whether the node is part of the current tree view image. It does not indicate whether or not the node is scrolled into view when the tree view image is larger than the size of the tree view control.

Item

property Item[Index: Integer]: TTreeNode;

Use Item to access a child node based on its Index property. The first child node has an index of 0, the second an index of 1, and so on.

ItemId

property ItemId: HTreeItem;

Use this property to reference the nodes when making Windows API calls or calling the GetNode method of the TTreeNodes that owns the item.

Level

property Level: Integer;

The value of Level is 0 for nodes on the top level. The value of Level is 1 for their children, and so on.

OverlayIndex

property OverlayIndex: Integer;

An overlay mask is an image drawn transparently over another image in the tree view. For example, to indicate that a node is no longer available, use an overlay image that puts an X over the current node's image.

Owner

property Owner: TTreeNodes;

Use the Owner property to determine the owner of the tree node. Do not confuse Owner with the TreeView property. Owner is the list of nodes used by the tree view to manage its nodes. The TreeView property is the tree view that uses that list.

Parent

property Parent: TTreeNode;

A Parent node is one level higher than the node and contains the node as a subnode.

Selected

property Selected: Boolean;

Set Selected to true to select the node. The appearance of a selected node depends on whether it has the focus and on whether the system colors are used for selection. When a node becomes selected, the tree view's OnChanging and OnChanged events are triggered.

SelectedIndex

property SelectedIndex: Integer;

Use the SelectedIndex property to specify an image to display when the tree node is selected.

StateIndex

property StateIndex: Integer;

Use StateIndex to display an additional image for the node that reflects state information. If StateIndex is -1 then no state image is drawn.

Text

property Text: string;

Use Text to specify the string that is displayed in the tree view. The value of Text can be assigned directly at run-time or can be set within the TreeView Items Editor while modifying the Items property of the TTreeView component. If the tree view allows users to edit its nodes, read Text to determine the value given the node by the user.

TreeView

property TreeView: TCustomTreeView;

Use TreeView to determine the tree view associated with the tree node.

需要了解的方法:

AlphaSort

function AlphaSort(ARecurse: Boolean = False): Boolean;

AlphaSort triggers node sorting or resorting of the node’s child nodes. If an OnCompare event handler is defined for the associated TCustomTreeView, that routine determines sort order. If no OnCompare handler is defined, nodes are sorted by a simple case-sensitive compare of their captions.

The optional ARecurse parameter (default false) specifies that sorting should recursively descend the node tree and sort each subtree in turn. By default, only the node’s immediate children are sorted.

Calling AlphaSort is equivalent to calling CustomSort with a nil (Delphi) or NULL (C++) procedure parameter and a data parameter of 0.

To sort the top-level nodes, use the AlphaSort method of TTreeNodes.

Assign

procedure Assign(Source: TPersistent); override;

If the Source parameter is a TTreeNode object, Assign copies the Text, Data, ImageIndex, SelectedIndex, OverlayIndex, Focused, DropTarget, Cut, and HasChildren properties from the source node. If Source is any other type of object, Assign calls its inherited method, which copies information from any object that can copy to a tree node in its AssignTo method.

Note: While Assign copies the HasChildren property, it does not copy the child nodes. Be sure to copy any descendants after assigning the properties of another node that has children.

Collapse

procedure Collapse(Recurse: Boolean);

When a node is collapsed, all of its subnodes are hidden. The plus button may be displayed, depending on whether the tree view's ShowButtons property is set. If Recurse is true, then all subnodes will be collapsed as well. When the node is next expanded the children will still be collapsed. If Recurse is false, the child nodes won't be collapsed and the next time the node is expanded, the children will be in the same state as when Collapse was called.

Create

constructor Create(AOwner: TTreeNodes);

Call Create to instantiate a tree node at runtime. Nodes added to a tree view control at design time are created automatically. Use the methods of the TTreeNodes object instead to create nodes as part of an existing tree view.

After calling the inherited constructor, Create sets the OverlayIndex and StateIndex properties to -1 and then sets the Owner property of the tree node to the AOwner TTreeNodes object.

CustomSort

type

PFNTVCOMPARE = function(lParam1, lParam2, lParamSort: Longint): Integer stdcall;

TTVCompare = PFNTVCOMPARE;

function CustomSort(SortProc: TTVCompare; Data: Longint; ARecurse: Boolean = False): Boolean;

CustomSort triggers node sorting or resorting of the node’s child nodes, using a comparison routine indicated by the SortProc parameter. The Data parameter is passed to the comparison routine. The optional ARecurse parameter (default false) specifies that sorting should recursively descend the node tree and sort each subtree in turn.

If SortProc is nil (Delphi) or NULL (C++), a default comparison routine is used. The default routine uses the OnCompare event handler for the associated TCustomTreeview object, if defined. If the OnCompare event handler is not defined, the default routine uses a simple case-sensitive compare of node captions.

In the comparison routine, the lParam1 and lParam2 parameters refer to two nodes when cast to TTreeNode. The lParamSort parameter is the value previously passed to the Data parameter of CustomSort. The return value of the comparison routine indicates the relative sort order of IParam1 and IParam2:

!al(,3,TopicNotFound,main)

Return Value Meaning

!al(,3,TopicNotFound,main)

< 0 IParam1 comes before IParam2

!al(,3,TopicNotFound,main)

0 IParam1 and IParam2 are equivalent

!al(,3,TopicNotFound,main)

> 0 IParam2 comes before IParam1

To sort the top-level nodes, use the CustomSort method of TTreeNodes.

Delete

procedure Delete;

Use the Delete method to delete a tree node and free all associated memory.

DeleteChildren

procedure DeleteChildren;

Use the DeleteChildren method to delete all children of a tree node, freeing all associated memory.

Destroy

destructor Destroy; override;

Do not call Destroy directly in an application. Instead, use the Delete method. Delete removes the image of the node and all its children from the tree view window, and guards against recursive deletes.

DisplayRect

function DisplayRect(TextOnly: Boolean): TRect;

If the TextOnly parameter is true, the bounding rectangle includes only the text of the node. Otherwise, it includes the entire line that the node occupies in the tree-view control.

EndEdit

procedure EndEdit(Cancel Boolean);

Call EndEdit to take the node out of edit mode. If the Cancel parameter is true, all changes made by the user are discarded. If Cancel is false, EndEdit updates the node’s Text property and the tree view’s OnEdited event occurs.

Expand

procedure Expand(Recurse: Boolean);

When a node is expanded, its immediate subnodes are displayed. The minus '-' button may be displayed, depending on whether the tree view's ShowButtons property is set. If Recurse is true, all descendants of the immediate subnodes are expanded as well.

GetFirstChild

function GetFirstChild: TTreeNode;

Call GetFirstChild to access the first child node of the tree view node. If the node has no children, GetFirstChild returns nil (Delphi) or NULL (C++).

Note: GetFirstChild returns the same value as Item[0].

GetHandle

function GetHandle: HWND;

Calling GetHandle is the same as reading the Handle property.

GetLastChild

function GetLastChild: TTreeNode;

Call GetLastChild to find the last immediate child of a node. If the calling node has no children, GetLastChild returns nil (Delphi) or NULL (C++). GetLastChild returns the same value as Item[Count-1].

GetNext

function GetNext: TTreeNode;

If the calling node is the last node, GetNext returns nil (Delphi) or NULL (C++). Otherwise, it returns the next node including nodes that aren't visible and child nodes. To get the next node at the same level as the calling node, use GetNextSibling. To get the next visible node, use GetNextVisible.

GetNextChild

function GetNextChild(Value: TTreeNode): TTreeNode;

Call GetNextChild to locate the next node in the list of immediate children of the tree view node. If the calling node has no children or there is no node after Value, GetNextChild returns nil (Delphi) or NULL (C++).

getNextSibling

function GetNextSibling: TTreeNode;

GetNextSibling will return the next node, regardless of whether it's visible. To find the next node in the tree view including child nodes, use GetNext.

GetNextVisible

function GetNextVisible: TTreeNode;

Use GetNextVisible when iterating through all the visible nodes in the tree view. A node is visible if all its parent nodes are expanded.

GetPrev

function GetPrev: TTreeNode;

GetPrev will return the previous node whether or not it is visible. To get the previous visible node, use GetPrevVisible.

GetPrevChild

function GetPrevChild(Value: TTreeNode): TTreeNode;

Call GetPrevChild to locate the previous node in the list of immediate children of the tree view node. If the calling node has no children or there is no node before Value, GetPrevChild returns nil (Delphi) or NULL (C++).

GetPrevSibling

function GetPrevSibling: TTreeNode;

GetPrevSibling returns the previous sibling node, regardless of whether it's visible. To find the previous node in the tree view including all levels, use GetPrev.

GetPrevVisible

function GetPrevVisible: TTreeNode;

To get the previous node, including non-visible, use GetPrev.

HasAsParent

function HasAsParent(Value: TTreeNode): Boolean;

Use the HasAsParent method to determine if a node is a parent to a particular node.

IndexOf

function IndexOf(Value: TTreeNode): Integer;

Call IndexOf to obtain the position of a child node among the children of the calling node. If Value isn't an immediate child of the calling node, IndexOf returns -1. The first child node has an index on 0, the second an index of 1, and so on.

IsFirstNode

property IsFirstNode: Boolean;

IsFirstNode returns true for the first node, with no parent node or previous sibling.

MakeVisible

procedure MakeVisible;

MakeVisible makes the node visible to the user, expanding parent nodes and scrolling as necessary.

MoveTo

procedure MoveTo(Destination: TTreeNode; Mode: TNodeAttachMode);

The Destination parameter specifies a node that will be this node's parent or sibling after the move. The Mode parameter specifies the new relationship between this node and the destination node.

优质内容筛选与推荐>>
1、浅谈Generator和Promise原理及实现
2、用文本编辑器打开文本文件
3、戏谈单向链表判环
4、maven仓库
5、01-初学总结之《谭浩强C程序设计》


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号