delphi - 具有隐藏节点的 VirtualStringTree 行的颜色

标签 delphi delphi-xe2 virtualtreeview tvirtualstringtree

我目前在树的 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;

给我的节点着色。 但对于隐藏节点,这不起作用,因为索引保持不变。 是否有可见的索引或简单的解决方法?

提前致谢。

最佳答案

目前没有这样的方法来获取可见性节点索引。但是您可以创建自己的节点,在其中迭代可见节点并对每次迭代进行计数。像这样的东西(如何在实际代码中实现它取决于你):

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;

关于delphi - 具有隐藏节点的 VirtualStringTree 行的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26428920/

相关文章:

Delphi IDE 线长度

delphi - 向 Delphi 推荐新功能的最佳方式是什么?

delphi - 虚拟字符串树 4.8.7 HeaderDblClick 事件没有功能?

delphi - Delphi Xe2 中的通用排序出现错误

c++ - Delphi 库内存管理器奇怪

delphi - 重新声明自定义 Delphi 组件的 Width 属性

delphi - 如何检测表单大小调整何时开始和停止?

delphi - WIA 扫描时跳过设备选择对话框

delphi - 如何从 TStringList 添加到 VirtualTreeView?

delphi - VirtualTreeView 是否管理节点用户数据的内存,或者我可以吗?