RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TTreeNodes.AddChildObject Method

Adds a new tree node containing data to a tree view.

Pascal
function AddChildObject(Parent: TTreeNode; const S: string; Ptr: TCustomData): TTreeNode;
C++
__fastcall TTreeNode AddChildObject(TTreeNode Parent, const AnsiString S, TCustomData Ptr);

The node is added as the last child of the node specified by the Parent parameter. The S parameter specifies the Text property of the new node. The Ptr parameter specifies the Data property value of the new node. AddChildObject returns the node that has been added.

Note: The memory referenced by Ptr is not freed when the tree nodes object is freed.
 

C++ Examples: 

 

/*
The following example adds a new child to the selected
item’s list of child items in the tree view control. The new
item is identified by the text ‘New Item’. The TBitmap
object is attached to the new item.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  Graphics::TBitmap *MyBitMap =
    new Graphics::TBitmap();
  MyBitMap->LoadFromFile("..\\littleB16.bmp");
  TreeView1->Items->BeginUpdate(); // keep the node from painting until it's built
  TreeView1->Items->AddChildObject(
  TreeView1->Selected, "New Item", MyBitMap);
  TreeView1->Items->EndUpdate();
}

 

Delphi Examples: 

{
The following example adds a new child to the selected
item’s list of child items in the tree view control. The new
item is identified by the text ‘New Item’. The TBitmap
object is attached to the new item.
}
procedure TForm1.Button1Click(Sender: TObject);
var MyBitMap : TBitmap;
begin
  MyBitMap := TBitmap.Create;
  MyBitMap.LoadFromFile('littleB16.bmp');
  TreeView1.Items.BeginUpdate;  // keep the node from painting until it's built
  TreeView1.Items.AddChildObject(
    TreeView1.Selected, 'New Item', MyBitMap);
  TreeView1.Items.EndUpdate;
end;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!