1

当我按下按钮时,我试图将节点移动到顶部,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;
4

1 回答 1

4

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

Vts1.MoveTo(Node, Vts1.GetFirst, amInsertBefore, False);
于 2016-04-11T17:50:12.073 回答