TcxCustomTreeView.TopItem Property
Specifies the topmost visible tree node.
Declaration
property TopItem: TTreeNode read; write;
Property Value
Type |
---|
TTreeNode |
Remarks
When there are too many items displayed to fit into the control vertically, a vertical scroll bar is displayed. This enables end-users to scroll through the tree. If you need to determine the node which is currently the topmost visible, read the TopItem property value. This property also enables you to specify the topmost visible node programmatically. Thus you can scroll the tree view control vertically via code.
Here is an example of using the TopItem property. By default, when expanding a node, the control tries to scroll the view so that all child nodes are visible. You can avoid this effect by storing the top visible node when the node is about to be expanded and restoring it after the operation has been completed. The OnExpanding and OnExpanded events are used for this purpose.
var
CurrentNode: TTreeNode;
procedure TForm1.cxTreeView1Expanding(Sender: TObject; Node: TTreeNode;
var AllowExpansion: Boolean);
begin
CurrentNode := cxTreeView1.TopItem;
end;
procedure TForm1.cxTreeView1Expanded(Sender: TObject; Node: TTreeNode);
begin
cxTreeView1.TopItem := CurrentNode;
end;