Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

TcxCustomTreeView.TopItem Property

Specifies the topmost visible tree node.

#Declaration

Delphi
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.

Delphi
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;
See Also