应该是Ttreenode的展开:
AddChildToTreeView(nil);//增加树顶节点
AddChildToTreeView(trvUnitTree.TopItem);//为顶节点增加孩子
trvUnitTree.TopItem.Expand(true);//从顶节点自动展开
AddChildToTreeView的树创建过程:
procedure AddChildToTreeView(aParentNode: TTreeNode);
var
aNode: TTreeNode;
begin
if aParentNode = nil then
begin
//初始化树
trvUnitTree.Items.Clear;
trvUnitTree.OnChange := trvUnitTreeChange;
Application.ProcessMessages;
end;
//加载节点的孩子节点
if aParentNode <> nil then aParentNode.DeleteChildren;
if DBAccess.DoProcess('TUnitInfo', 'GetChildNode', GetTheNodeCode(aParentNode)) = -1 then
begin
HWShowMessage('获取数据失败!');
exit;
end;
with DBAccess.ResultDataSet do
begin
First;
while not Eof do
begin
aNode := trvUnitTree.Items.AddChild(aParentNode, FieldByName('unitname').AsString);//数据库表中必须要有父子关系
trvUnitTree.SetNodeData(aNode, FieldByName('unitnum').AsString);
Next;
end;
end;
end;