procedure Tcpya_app.FormCreate(Sender: TObject);
begin
datamodule2.tree.close;
datamodule2.tree.sql.clear;
datamodule2.tree.sql.add('select name from plat order by name');
datamodule2.tree.Active:=true;
datamodule2.tree.Open;
while not datamodule2.tree.Eof do
begin
with tv.Items do
begin
MyTreeNode1 := Add(nil,trim(datamodule2.tree.fIElds[0].asstring));//增加根節點
with datamodule2 do
begin
child.close;
child.SQL.Clear;
child.SQL.Add('select comp from dalei where plat='''+Trim(datamodule2.tree.FIElds[0].asstring)+''''+' order by comp');
child.Active:=true;
child.Open;
While Not child.Eof do
begin
TV.Items.AddChild(mytreenode1,trim(child.FIElds[0].AsString));
child.Next;
end; end;
datamodule2.tree.Next;
end;
end;
end;
在添加和刪除前必須保證有節點被選中(TreevIEw.Selected= nil)<?XML:namespace prefix = o ns = "urn:schemas-microsoft-com:office:Office" />
用Add,如:MyTreeNode1 := Add(nil,trim(datamodule2.tree.fIElds[0].asstring));
在添加子節點時用addchild(父節點,子節點名),
但在添加大量的數據的時候 最好使用
TreeVIEw.Items.BeginUpdate;
添加節點
TreeVIEw.Items.EndUpdate
刪除節點
TreevIEw.Selected.Delete
編輯節點內容
TreevIEw.Selected.EditText