MartinLoanel
MartinLoanel

Reputation: 184

How do i move specific node to the first index?

i am trying to move a node to the top of TVirtualStringTree when i press on a button so first thing i do is search for the node by the following code

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;

then i set the procedure to be able to check if node equals for example "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;

Upvotes: 1

Views: 428

Answers (1)

Ken White
Ken White

Reputation: 125767

As was mentioned in a coment, use MoveTo:

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

Upvotes: 4

Related Questions