//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "TreeViewAddChild.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: TreeViewAddChild
// Method: ComCtrls.TTreeNodes.Add
// Method: ComCtrls.TTreeNodes.AddChild

// BeginCode
/*
The following example demonstrates how to add nodes and
child nodes to a TTreeView control.
*/
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TTreeNode *Node1;
  TreeView1->Items->Clear(); // remove any existing nodes
  // Add a root node
  TreeView1->Items->Add(NULL, "RootNode1");

  /* Set MyTreeNode to first node in tree view and add a child node to it */
  Node1 = TreeView1->Items->Item[0];
  TreeView1->Items->AddChild(Node1,"ChildNode1");

  // Add another root node
  TreeView1->Items->Add(Node1, "RootNode2");

  /* Reset Node1 to RootNode2 and add a child node to it */
  Node1 = TreeView1->Items->Item[2];
  TreeView1->Items->AddChild(Node1,"ChildNode2");

  /* Reset Node1 to ChildNode2 and add a child node to it */
  Node1 = TreeView1->Items->Item[3];
  TreeView1->Items->AddChild(Node1,"ChildNode2a");

   /* Add another child to ChildNode2 following ChildNode2a */
  TreeView1->Items->AddChild(Node1,"ChildNode2b");

  // add another root node
  TreeView1->Items->Add(TreeView1->Items->Item[0], "RootTreeNode3");
}
// EndCode
// EndExample: TreeViewAddChild
//---------------------------------------------------------------------------
