//两层的,多层的你自己改吧 ,递归调用
procedure TForm1.Button1Click(Sender: TObject);
var
l_ND : TTreeNode;
begin
with Query1 do
begin
Close;
SQL.Text := 'select distinct id, show from table1 order by id';
Open;
while not Eof do
begin
l_ND := TreeView1.Items.Add(nil, FieldByName('Show').AsString);
with Query2 do
begin
Close;
SQL.Text := 'select id, show from table1 where parent=' + QuotedStr(Query1.FieldByname('ID').AsString);
Open;
while not eof do
begin
TreeView1.Items.Add(l_ND, FieldByName('Show').AsString);
Next;
end;
Close;
end;
Next;
end;
Close;
end;
end;