Color VirtualStringTree rows with hidden nodes

丶灬走出姿态 提交于 2019-12-07 07:30:39

问题


I'm currently using this code in the OnBeforeCellPaint event of my tree:

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;

To color my nodes. But with hidden nodes this doesn't work as the index stays the same. Is there an visible index or an easy workaround?

Thanks in advance.


回答1:


There is no such method to get visibility node index at this time. But you can make your own where you will iterate through the visible nodes and count each iteration. Something like this (how you implement it in real code is upon you):

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;


来源:https://stackoverflow.com/questions/26428920/color-virtualstringtree-rows-with-hidden-nodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!