为VirtualStringTree带有隐藏节点的行上色 [英] Color VirtualStringTree rows with hidden nodes

查看:129
本文介绍了为VirtualStringTree带有隐藏节点的行上色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前在树的OnBeforeCellPaint事件中使用以下代码:

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?

谢谢.

推荐答案

目前尚无此类方法可获取 visibility 节点索引.但是,您可以自己创建要遍历可见节点的位置,并计算每次迭代的次数.这样的事情(如何在实际代码中实现它就在您身上):

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;

这篇关于为VirtualStringTree带有隐藏节点的行上色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆