Skip to main content

TcxCustomTreeView.OnAddition Event

Fires in response to adding a node to the tree view control.

Declaration

property OnAddition: TTVExpandedEvent read; write;

Remarks

Handle the OnAddition event to perform specific actions each time a node is added to the tree view control.

Sender specifies the TcxCustomInnerTreeView.

Node represents the added node.

Handling the OnAddition event is useful, for instance, if you allow end-users to add nodes to the tree view control and want to correct node settings on insert.

Note that you can load the node structure from a stream or a file. This can be performed using the LoadFromStream and LoadFromFile methods respectively. If using these methods, the OnAddition event fires for each loaded node. Thus, you can handle the event to correct node settings. This is useful since the mentioned methods allow you to load only the structure of nodes and their captions. The OnAddition event enables you to specify any other data associated with the loaded nodes (for instance, image indexes).

Note

Individual nodes can be added to the tree view control using methods of the TTreeNodes object available via the Items property of the control.

The sample code below handles the OnAddition event to add indexes to node captions.

procedure TForm1.cxTreeView4Addition(Sender: TObject; Node: TTreeNode);
var
  ParentNode: TTreeNode;
  Number: string;
begin
  ParentNode := Node;
  Number := IntToStr(Node.Index + 1);
  while ParentNode.Parent <> nil do
  begin
    ParentNode := ParentNode.Parent;
    Number := IntToStr(ParentNode.Index + 1) + '.' + Number;
  end;
  Node.Text := Number + ' - ' + Node.Text;
end;

Here is the result of code execution. Note the composite indexes of nodes:

If you need to handle node deletion, use the OnDeletion event.

See Also