//这是在当前选中项目添加新项目的代码
var
Node1: TTreeNode;
begin
sTreeView1.Items.AddChild(Node1, 'New Item');
end;
[Delphi] 纯文本查看复制代码
这个。。。。。是向前添加的。。。也有问题
procedure TMDIChild.N4Click(Sender: TObject);
var
MyTreeNode1: TTreeNode;
begin
with STreeView1.Items do
begin
//MyTreeNode1 := Add(nil, 'RootTreeNode1');
MyTreeNode1 := Add(nil, STreeView1.Selected.Text);
AddChild(MyTreeNode1, 'ChildNode1');
end;
procedure TMDIChild.N4Click(Sender: TObject);
var
MyTreeNode1, MyTreeNode2: TTreeNode;
begin
with STreeView1.Items do
begin
// Clear; //删除任何现有节点
{添加根节点
将子节点添加到刚才添加的节点}
//MyTreeNode1 := Add(nil, 'RootTreeNode1');
MyTreeNode1 := Add(nil, STreeView1.Selected.Text);
procedure TMDIChild.N1Click(Sender: TObject);
var
MyNode: TTreeNode;
i: integer;
begin
with STreeView1.Items do
begin
MyNode := STreeView1.items[i];
AddChild(MyNode, '1111111');
end;
end;
又改了一下,还是有bug
procedure InsertAfter(aTree:TTreeView; aText: String);
var
nodeThat: TTreeNode;
begin
nodeThat := aTree.Selected.GetNext;
if nodeThat=nil then
aTree.Items.Add(aTree.Selected, aText)
else
aTree.items.Insert(nodeThat, aText);
end;