to lyplay2,
我是有找到,但发现用索引过滤并不快!和我第一种差不多快!不知为什么!
程序如下:
procedure TFrmcostmaterial.FormShow(Sender: TObject);
var
leaf,subNode: TTreeNode;
tv: TRzTreeView;//引用窗体控件
qry: TADOQuery;//引用窗体控件
procedure AddChildNode(ANode :TTreeNode);
begin
while (ANode <> nil) do
begin //while ANode is not empty
if ANode.Level =0 then
qry.Filter := 'materialparent=1'
else
qry.Filter :=Format('materialparent=%d',[ANode.StateIndex]);
qry.Filtered := True;
if not qry.Eof then
begin //not for empty
while not qry.Eof do
begin //while
with tv.Items.AddChild(ANode,'['+qry.fieldbyname('materialcode').AsString+']'+qry.FieldByName('materialname').AsString
) do
begin
StateIndex := qry.FieldByName('materialid').asinteger;
if qry.fieldbyname('bisended').AsBoolean then
ImageIndex:=1
else
ImageIndex:=0 ;
end;
qry.Next;
end; //while
AddChildNode(ANode.getFirstChild); // 递归
end; //not for empty
ANode := ANode.getNextSibling;
end; //while ANode is not empty
end;
begin
//新算法
tv:=RzTreeView1;
qry:=qmaterial;
tv.Items.BeginUpdate ;
Screen.Cursor := crSQLWait;
try
tv.Items.Clear;
subNode:=tv.Items.AddChild(nil,'['+'Material'+']'+'基本材料资料');
if qry.Active then qry.Active :=false;
qry.SQL.Text :='select * from material where materialparent>0 order by materialparent,materialcode ' ;
qry.Active :=true;
AddChildNode(tv.Items.GetFirstNode);
//新算法
finally
tv.Items.EndUpdate ;
Screen.Cursor := crDefault;
end;