【问题标题】:How do i move specific node to the first index?如何将特定节点移动到第一个索引?
【发布时间】:2016-04-11 13:14:25
【问题描述】:

当我按下按钮时,我试图将节点移动到 TVirtualStringTree 的顶部,所以我首先要做的是通过以下代码搜索节点

function Tform1.lookingTreeView(name: String): PVirtualNode;
var
  Node: PVirtualNode;
  Data: PUserData;
begin
  Result := nil;
  Node := Vts1.GetFirst;
  while ((Node <> nil) and (Result = nil)) do
  begin
    Data := Vts1.GetNodeData(Node);
    if (Tuserdataclass(Data.FObject).userUid = name) then
      Result := Node;
    Node := Vts1.GetNext(Node);
  end;
end;

然后我将程序设置为能够检查节点是否等于例如 "Martin"

procedure Tform1.checkmove;
var
  Node: PVirtualNode;
  Data: PUserData;
begin

  Node := lookingTreeView(LineToid);

  if not Assigned(Node) then
    Exit;
  if (Node <> nil) then
  begin
    Data := vts1.GetNodeData(Node);
    if Tdataclass(Data.FObject).name = 'Martin' then
    begin

      // start move but dont know what to do to bring this node to first index

    end;
  end;
end;

【问题讨论】:

  • 您可能希望更好地格式化您的代码,以便人们实际上可以更好地阅读它。
  • @RudyVelthuis 代码格式化
  • 好多了,谢谢。
  • Vts1.MoveTo(Node, Vts1.GetFirst, amInsertBefore, False);

标签: delphi delphi-xe7 virtualtreeview tvirtualstringtree


【解决方案1】:

正如评论中提到的,使用MoveTo

Vts1.MoveTo(Node, Vts1.GetFirst, amInsertBefore, False);

【讨论】:

    猜你喜欢
    • 2021-12-15
    • 2021-07-17
    • 1970-01-01
    • 1970-01-01
    • 2017-03-20
    • 2020-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多