2014-10-17 63 views
4

我目前使用此代码在我的树的OnBeforeCellPaint事件:颜色VirtualStringTree行与隐藏节点

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; 

颜色我的节点。 但由于索引保持不变,隐藏节点不起作用。 有没有可见的索引或简单的解决方法?

在此先感谢。

回答

4

目前没有这样的方法可以获得的可见性节点索引。但是你可以让自己的位置遍历可见节点并计算每次迭代。像这样的东西(你如何以实际代码实现它):

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;