How to prevent a certain Virtual StringTree NodeLevel from being dragged?

What I am trying to accomplish

I have got a virtual stringtree with sublevel rows that can be expanded by the user. The top hierarchy level of all nodes shall be draggable. But none of the sub node levels shall be.

How to test

For testing I use the Advanced Demo project of the current Virtual TreeView revision. The second demo (General abilities and features) has an adequate node hierarchy and you can drag nodes around.

Consideration

I thought I would be able to accomplish my task by using the stringtree's OnDragAllowed event but it isn't fired when I am dragging. My intention is to check the node level ( GetNodeLevel ) before dragging starts and only allow dragging for the top node level 0.

How can I prevent certain node levels of a virtual stringtree from being dragged?


For the sake of an answer ... all credit goes to TLama.

To prevent a certain node level from being dragged we can implement the OnDragAllowed event handler and make sure to also have the StringTree's DragMode set to dmManual .

Here is the event handler.

procedure TForm1.vstDragAllowed(Sender: TBaseVirtualTree; Node: PVirtualNode;
  Column: TColumnIndex; var Allowed: Boolean);
begin
  { dragging shall only be possible for top nodes (level 0) }
  Allowed := TVirtualStringTree(Sender).GetNodeLevel(Node) = 0;
end;

The basics and implications of Drag and Drop are described in this Delphi About.com article.

链接地址: http://www.djcxy.com/p/35086.html

上一篇: 如何获得Delphi的TQuery结果?

下一篇: 如何防止拖动某个虚拟StringTree NodeLevel?