德尔福 – VitrtualStringTree.如何Drag’n’Drop到ROOT水平?

有一棵树:
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;

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

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

解决方法

您还没有显示您的代码,但基本上,当您的OnDragDrop事件方法的(drop)Mode参数等于dmNowhere时,您只需要为Moveto方法调用使用正确的(attach)Mode参数,这表示用户只是将节点删除到树的空白区域.我假设你有一个像下面的代码来确定你的OnDragDrop事件方法中的附加模式:

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;

如果是这样,你可以告诉树附加节点,例如如果丢弃模式为dmNowhere,则将附加模式更改为amAddChildLast作为最后一个子节点:

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;

相关文章

/etc/sysctl.conf这个目录主要是配置一些系统信息,/etc/sys...
1.作用 useradd或adduser命令用来建立用户帐号和创建用户的起...
它们都是多模式编辑器,不同的是vim 是vi的升级版本,它不仅...
不管是我们在安装软件还是监测软件的使用性能,我们都要随时...
装好Tomcat7后,发现除了本机能访问外界访问不了,岂有此理。...
修改防火墙配置需要修改 /etc/sysconfig/iptables 这个文件,...