C
chenp1688
Unregistered / Unconfirmed
GUEST, unregistred user!
各位老师,真不好意思了,这个问题我问了很多次了,可一直没有做到最佳,然后搜了了一段代码,改了改,还是达不到要求,主要是这样如,计量单位 重量组 数据组如果我新增一个组的时候它不会显示在"数量组"的后面,而是显示在"重量组"前面.新增子节也一样,都是在第一个位置加起,而我要求的是向后加,希望那位高手帮帮我吧,帮我看看吧!(如果可以,我愿付费) procedure MakeTree(cdstree:TADODataSet;TableName:string;TreeView:TTreeView;FID:integer);var Node:TTreeNode; Index:Integer;begin cdstree.Close; cdstree.commandtext:='SELECT * FROM ' + TableName + ' where FItemClassID='+inttostr(FID)+' ORDER BY FItemID '; //ORDER BY FnumberID FnumberID ,FParentID,FItemID cdstree.Open; TreeView.Items.BeginUpdate; try TreeView.Items.Clear; List:=TStringList.Create; try List.Sorted:=True; cdsTree.First; while not cdsTree.Eof do begin //如果是顶接点 if cdsTree.FieldByName('FParentID').AsInteger=0 then begin Node:=TreeView.Items.AddChild(nil,cdsTree.FieldByName('Fname').AsString); end else begin Index:=List.IndexOf(cdsTree.FieldByName('FParentID').AsString); Node:=TreeView.Items.AddChildFirst(TTreeNode(List.Objects[index]),cdsTree.FieldByName('Fname').AsString); end; List.AddObject(cdsTree.FieldByName('FItemID').AsString,Node); cdsTree.Next; end; finally List.Free; cdsTree.Close; end; finally TreeView.Items.EndUpdate; node.Expand(false); end;end;