【问题标题】:Color VirtualStringTree rows with hidden nodes为具有隐藏节点的 VirtualStringTree 行着色
【发布时间】:2014-12-13 06:25:00
【问题描述】:
我目前在我的树的 OnBeforeCellPaint 事件中使用此代码:
if Node.Index mod 2 = 0 then
begin
TargetCanvas.Brush.Color := clBlack;
TargetCanvas.FillRect(CellRect);
end
else
begin
TargetCanvas.Brush.Color := clPurple;
TargetCanvas.FillRect(CellRect);
end;
为我的节点着色。
但是对于隐藏节点,这不起作用,因为索引保持不变。
是否有可见的索引或简单的解决方法?
提前致谢。
【问题讨论】:
标签:
delphi
delphi-xe2
virtualtreeview
tvirtualstringtree
【解决方案1】:
目前没有这样的方法来获取visibility节点索引。但是您可以创建自己的地方,您将在可见节点中进行迭代并计算每次迭代。像这样的东西(你如何在实际代码中实现它取决于你):
function GetVisibleIndex(Tree: TBaseVirtualTree; Node: PVirtualNode): Integer;
var
P: PVirtualNode;
begin
Assert(Assigned(Node), 'Node must not be nil!');
Assert(Tree.IsVisible[Node], 'Node must be visible!');
Result := 0;
P := Tree.GetFirstVisible;
while Assigned(P) and (P <> Node) do
begin
Inc(Result);
P := Tree.GetNextVisible(P);
end;
end;