声明:下面代码调试通过
新建一个空的工程,
新添一个TreeView1控件,不要做任何改动(包括手工添结点)
然后在一个button里执行如下代码:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
TTreeNode *Node1;
TreeView1->Items->Clear(); // remove any existing nodes
// Add a root node
TreeView1->Items->Add(NULL, "aa");
/* Set MyTreeNode to first node in tree view and add a child node to it */
Node1 = TreeView1->Items->Item[0];
TreeView1->Items->AddChild(Node1,"11");
TreeView1->Items->AddChild(Node1,"33");
// Add another root node
TreeView1->Items->Add(Node1, "bb");
/* Reset Node1 to RootNode2 and add a child node to it */
Node1 = TreeView1->Items->Item[3];
TreeView1->Items->AddChild(Node1,"11");
TreeView1->Items->AddChild(Node1,"22");
/*下面是你需要在aa中的11和33之间插入一个节点22,你可以去掉下面代码以作测试,试试看是否是你需要的功能*/
Node1 = TreeView1->Items->Item[2];
Node1 = TreeView1->Items->Insert(Node1, "22");
}
好了,分来吧