2014-10-17 50 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;