我正在使用虚拟树视图。有没有可靠的方法来知道节点是否是根节点?
我尝试使用
if not Assigned(Node.Parent) then
Output('This is root')
else
Output('This is not root')
但不起作用。
我尝试使用
if Node = tvItems.RootNode then
Output('This is root')
else
Output('This is not root')
但也不起作用。
最终根节点为VTV
(or VST
)是一个特殊的不可见节点,它充当所有用户创建的根节点(使用parent = nil
)。这个特殊的隐形节点被设计为NextSibling
and PrevSibling
属性设置为指向自身。
要检测节点是否是根节点(在用户创建根的意义上),您可以例如:做:
procedure TForm16.tvItemsNodeClick(Sender: TBaseVirtualTree;
const HitInfo: THitInfo);
begin
if HitInfo.HitNode.Parent.NextSibling = HitInfo.HitNode.Parent then
Caption := 'Root node'
else
Caption := 'Not root node';
end;
或者,正如OP评论的那样,并且不使用内部实现细节:
procedure TForm16.tvItemsNodeClick(Sender: TBaseVirtualTree;
const HitInfo: THitInfo);
begin
if HitInfo.HitNode.Parent = Sender.RootNode then
Caption := 'Root node'
else
Caption := 'Not root node';
end;
参考:TBaseVirtualTree.RootNode 属性(在帮助中)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)