Home > Back-end >  Use onexpanded add child nodes to the tree
Use onexpanded add child nodes to the tree

Time:10-08

This is the event code:

Procedure TForm1. TreeView1Expanded (Sender: TObject; Node: TTreeNode);
Var
S1, s2: string;
Node1: ttreenode;
The begin
{to remove the original pretend child node space value}
//showmessage (node. Item [0]. The text).
If the trim (node. Item [0]. The Text)='then
After the begin//that is executed once recorded there, if you don't have the begin end limit will add the same record below, this is not to need to trigger the execution,
Node. The Item [0]. Delete;

S1:=copy (node. The Text, 1, posex (' _ ', node. The Text, 1) - 1);//looking for from the first position, find the position so far ahead of the '-',
//showmessage (s1);
Adoquery1. Close;
Adoquery1. SQL. Text:='select * from sys_menu where parentnodeid=: p1';
Adoquery1. The Parameters. ParamByName (' (p1). The Value:=s1;
Adoquery1. Open;

While not adoquery1. Eof do
The begin
S1:=trim (adoquery1 FieldByName (' menuID). Asstring) are identical.
S2:=trim (adoquery1 FieldByName (' menutitle). AsString) are identical.
Node1:=treeview1. Items. AddChild (node, s1 + '_' + s2);

If (adoquery1 FieldByName (' isparentflag). Asinteger=1) then
The begin
Treeview1. Items. AddChild (node1, s1 + '_' + s2);
end;
Adoquery1. Next;

end;
end;


end;

This is make to the effect of the code:

That is to say, the third layer is wrong,
Is it because treeview1. Item [0]. Text='this judgment reason,?
How to change?

CodePudding user response:

//showmessage (s1); The s1 right?
  • Related