Web forum is in read-only mode. Login as active registered customer for write access
  Forum Search   New Posts New Posts

Dragcursor in Drag&Drop in TAdvTreeView

 Post Reply Post Reply
Author
Ronald Janse View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 Aug 2015
Posts: 272
Post Options Post Options   Quote Ronald Janse Quote  Post ReplyReply Direct Link To This Post Topic: Dragcursor in Drag&Drop in TAdvTreeView
    Posted: 05 Nov 2019 at 11:43am
I have a working Drag & Drop in a TAdvTreeView, using BeforDropNode and AfterDropnode. The only thing I am missing is a way to change the Dragcursor when a dragged node is over a node that it can't be dropped upon.
I tried this, but that did not work:
procedure TForm1.TVBeforeDropNode(Sender: TObject; AFromNode, AToNode: TAdvTreeViewVirtualNode;
  var ACanDrop: Boolean);
begin
  ACanDrop := ((AToNode <> NIL) and
              (AToNode.Extended) and
              ((AToNode.Children = 0) or (not AToNode.Node.Nodes[0].Extended)));
  if not ACanDrop then TV.DragCursor := crNoDrop else TV.DragCursor := crDrag;
end;

The obvious question is: how can I achieve this?
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3399
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2019 at 1:54pm
Hi,

You can use the following code to achieve this:

type
  TAdvTreeViewOpen = class(TAdvTreeView);

procedure TForm1.DoCustomDragOver(Sender, Source: TObject; Point: TPointF;
  var Accept: Boolean);
var
  n: TAdvTreeViewVirtualNode;
begin
  n := AdvTreeView1.XYToNode(Point.X, Point.Y);
  if Assigned(n) and (n.Level = 0) then
    Accept := False
  else
    Accept := True;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  AdvTreeView1.Interaction.DragDropMode := tdmMove;
  TAdvTreeViewOpen(AdvTreeView1).OnCustomDragOver := DoCustomDragOver;
end;


Edited by Pieter Scheldeman - 05 Nov 2019 at 1:54pm
Back to Top
Ronald Janse View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 Aug 2015
Posts: 272
Post Options Post Options   Quote Ronald Janse Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2019 at 2:31pm
Hi, I tried this and it works great. Thank you!
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3399
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 05 Nov 2019 at 4:00pm
Superb!
Back to Top
Ronald Janse View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 Aug 2015
Posts: 272
Post Options Post Options   Quote Ronald Janse Quote  Post ReplyReply Direct Link To This Post Posted: 18 Nov 2019 at 10:07am
I experience something strange when Dropping the Node and using the AfterDropNode event.
I expected the AFromNode to be the Node that is Dropped and the AToNode to be the Node that is dropped upon. When I drop, the AToNode is correct, but the AFromNode seems to miss some parameters. I use non-virtual nodes, so I have to use this construction if I want to know which Node is dropped upon which node by using their DBKeys:
procedure TFormItems.TVAfterDropNode(Sender: TObject; AFromNode, AToNode: TAdvTreeViewVirtualNode);
begin
    ShowMessage('from=' + AFromNode.Node.DBKey + '  to=' + AToNode.Node.DBKey);
end;

But in this case the AFromNode does not have a node. It is nil. So I don't have a DBKey either, which gives me an acces-violation.
I use TAdvTreeView 1.1.4.2.
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3399
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 19 Nov 2019 at 9:56am
In the OnAfterDropNode, the node are already switched. You can use the OnBeforeDropNode and the AFromNode and AToNode are still the original ones before switching.
Back to Top
Ronald Janse View Drop Down
Senior Member
Senior Member
Avatar

Joined: 20 Aug 2015
Posts: 272
Post Options Post Options   Quote Ronald Janse Quote  Post ReplyReply Direct Link To This Post Posted: 19 Nov 2019 at 10:08am
But does the OnBeforeDropNode event occur only once, just like the OnAfterDropNode event? I want to use this event to do some housekeeping after the drop. But I need something from the original Node. I can do that in the OnBeforeDropNode event as well, but I must be sure it only occurs once. Now I only use it to determine if ACanDrop is True.
Back to Top
Pieter Scheldeman View Drop Down
TMS Support
TMS Support
Avatar

Joined: 18 May 2010
Posts: 3399
Post Options Post Options   Quote Pieter Scheldeman Quote  Post ReplyReply Direct Link To This Post Posted: 19 Nov 2019 at 10:14am
It only occurs once.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down