VitrtualStringTree.如何Drag'n'Drop到ROOT水平?

Ale*_*ndr 4 delphi virtualtreeview delphi-xe tvirtualstringtree delphi-xe4

有一棵树:ROOT - VirtualStringTree(你看不到它,TVirtualStringTree.RootNode)

  • 我的根节点1
  • 我的根节点2
    • 第二节点1
    • 第二节点2
    • 第二节点3
  • 我的根节点3

我可以Drag'n'Drop"我的根节点3"到任何可见节点,但我不能将它返回到defaut位置,到树的根级别.

我试着这样:

//Part of code from OnDragDrop Event of VirtualStringTree
    if (Sender.DropTargetNode = Sender.RootNode) then
    begin
      for i := 0 to high(Nodes) do
      begin
        LinksTree.MoveTo(Nodes[i], Sender.DropTargetNode, Attachmode, False);
      end;
    end;
Run Code Online (Sandbox Code Playgroud)

我把鼠标放到了无处,但没有任何反应.在DragOver中,如果DropTarget是VST.RootNode,则接受drop to root.

谁知道,如果我将鼠标拖动到组件的空白区域,如何将节点删除到VST.RootNode?

TLa*_*ama 6

您还没有显示您的代码,但基本上,当您的事件方法的(drop)参数等于时,您只需要ModeMoveTo方法调用使用正确的(attach)参数,这表示用户刚刚删除了节点(s)到树的空地.我假设你有一个像下面这样的代码来确定你的事件方法中的附加模式:ModeOnDragDropdmNowhereOnDragDrop

var
  ...
  AttachMode: TVTNodeAttachMode;
begin
  ...
  // the Mode here is a drop mode parameter
  case Mode of
    dmNowhere: AttachMode := amNoWhere; // <- where this stands for no move
    ...
  end;
  ...
end;
Run Code Online (Sandbox Code Playgroud)

如果是这样的话,你可以通过改变附加模式告诉树连接节点,例如作为最后一个孩子,amAddChildLast如果丢弃模式是dmNowhere:

var
  ...
  AttachMode: TVTNodeAttachMode;
begin
  ...
  // the Mode here is a drop mode parameter
  case Mode of
    dmNowhere: AttachMode := amAddChildLast; // <- attach node as a last child
    ...
  end;
  ...
end;
Run Code Online (Sandbox Code Playgroud)