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 mytreenode 1: = add (nil, trim (datamodule2.tree.fields [0] .sstring)); // Increase root Node with DataModule2 Do Begin CHild.close; child.sql.clear; child.sql.add ('Select Comp from Dalei Where Plat =' ' Trim (DataModule2.tree.fields [0] .sstring) ' '' ' ' ORDER BY COMP '); Child.active: = true; child.open; while not child.eof do begin tv.items.addchild (MytReenode1, Trim (child.fields [0] .sstring); child. NEXT; END; DATAMODULE2.TREE.NEXT; END;
There must be a node to be selected before adding and deleting (TreeView.selected = NIL)
Use add, such as Mytreenode1: = add (nil, trim (datamodule2.tree.fields [0] .sstring));
Use AddChild (parent node, child node),
But it is best to use when adding a lot of data.
TreeView.Items.beginupdate;
Add node
TreeView.Items.Endupdate
Delete node
TreeView.selected.delete
Edit node content
TreeView.selected.editText