这是左右手以前写的一个,功能实现了,但节点多了效率不太好。
procedure AddSectionIntoView(SectionView: TTreeView1;
ImageIndex: integer;
ParentNode: TTreeNode;
OwnerForm: TForm;
ParentID:string);
var
TempQuery: TADOQuery;
CurrNode: TTreeNode;
begin
TempQuery := TADOQuery.Create(OwnerForm);
try
TempQuery.Connection := FormMain.ADOConnection1;
TempQuery.Close;
TempQuery.SQL.Text := 'select * from SectionInfo where ParentID=
arentID';
TempQuery.Parameters[0].Value := ParentID;
TempQuery.Open;
if TempQuery.RecordCount > 0 then
begin
TempQuery.First;
while not TempQuery.Eofdo
begin
CurrNode := SectionView.Items.AddChild(ParentNode,TempQuery.FieldValues['SectionName']);
CurrNode.ImageIndex := ImageIndex;
CurrNode.SelectedIndex := ImageIndex;
AddSectionIntoView(SectionView,ImageIndex,CurrNode,OwnerForm,TempQuery.FieldValues['SectionID']);
TempQuery.Next;
end;
end;
finally
TempQuery.Free;
end;
end;