TADVTreeview drag drop

How do you implement drag drop in TADVTreeview?


the DragMode property is not there. There is nothing about drag drop in the manual that I can see.

Thanks

Dave Craggs

Hi, 


To turn on drag & drop between 2 instances of TAdvTreeView, set the Interaction.DragDropMode = tdmCopy or tdmMove. To reoder inside a TAdvTreeView, set Interaction.Reorder := True

Thanks - will give that a go,


Dave

Hmm - might be an issue with EndDrag. Doesn't seem to be being called.


Using startdrag/enddrag to create a dragobject. StartDrag is being called, but not showing the dragimage. EndDrag is not being called so the image is not freed and I get a memory leak. 

Currently on version 8.3.0.0

Dave

Can't seen to display a dragimage. I have this working with frames. How are you supposed to display a drag image?


Dave

Anyone here?


We are currently investigating this

Thanks.


Dave

Can you post us your code that you are using to start a drag operation?

procedure TframePageEditor.treeToolboxStartDrag(Sender: TObject; var
    DragObject: TDragObject);
var
  b: tBitmap;
  lHeight: Integer;
  lWidth: Integer;
  p:TPoint;
  lNode: TAdvTreeViewNode;
begin
  if Assigned(FDragObject) then
     FreeAndNil(FDragObject);  // this should be freed in treeToolboxEndDrag but it is not being called

  // Drag object not being displayed. Checking with TMS

  p:=screentoclient(mouse.cursorpos);
  lHeight := 500;
  lWidth := 500;
  ImageListForDrag.clear;
  ImageListForDrag.height:=lHeight;
  ImageListForDrag.width:=lWidth;
  b:=tBitmap.create;
  try
  b.width:=lWidth;
  b.height:=lHeight;
  with b.canvas do
  begin
    brush.color:=clDkGray;
    brush.style:=bssolid;
    rectangle(0,0,lWidth,lHeight);
    end;
  if ImageListForDrag.Add(b,nil)<0 then showmessage('Dragmage add failed');
  finally
    b.Free;
  end;

  ImageListForDrag.setdragimage(0,p.x,p.y);

  FDragObject := TTreeDashDragObject.Create(Self); //Create the drag object
  DragObject := FDragObject;
end;

Hi, 


Can you post a complete sample so we can investigate this here? We have tested this with the latest version of the TAdvTreeView and the OnEndDrag event is called. Did you set AdvTreeView1.Interaction.DragDropMode to tdmCopy or tdmMove?

I am on version 8.3.0.0 - could that be the issue?


Also having problems with nodes getting 'stuck' where clicking does not expand. Using the arrow keys works.

Have updated to 8.4.0.0 and the nodes getting 'stuck' seems to have gone.


I have sorted the drag image problem.

But OnEndDrag is still not getting called. Seems to happen when you assign a dragobject.

  FDragObject := TTreeDashDragObject.Create(Self); //Create the drag object
  DragObject := FDragObject;

Dave

There have been some significant fixes for the TAdvTreeView in TMS Component Pack 8.4, the version history list can be consulted at the TMS Component Pack page, when clicking version history

Regarding the DragObject issue, can you provide a simple example that demonstrates the OnEndDrag is not being called, we are not able to reproduce this here.

If I get a moment. Got a tight schedule at the moment.


But it just seems to be adding the following to OnStartDrag  

  FDragObject := TTreeDashDragObject.Create(Self); //Create the drag object
  DragObject := FDragObject;

Where FDragObject is:

type
  TTreeDashDragObject = class(TDragControlObject)
  end;

Hi, 


We have investigated this here, but you need to pass the AdvTreeView1 as the AControl parameter of the dragobject. The drag object is responsible for calling the OnEndDrag. Passing Self will try to trigger the OnEndDrag event of the form instead. Please change the code to 

procedure TForm1.AdvTreeView1StartDrag(Sender: TObject;
  var DragObject: TDragObject);
begin
  FDragObject := TTreeDashDragObject.Create(AdvTreeView1); //Create the drag object
  DragObject := FDragObject;
end;

In order to call the OnEndDrag of the AdvTreeView instance instead.

Thanks,


The issue is how to pass the DragImage

The objects I am currently passing are frames

These override the protected method

    function GetDragImages: TDragImageList; override;

I don't want to get into overriding TADVTreeview to add this functionality. Is there another way?

Not a big issue now as I have worked out how to free the DragObject so the memory leak has gone and it is working using  the frames.

Dave

When returning a DragObject, you need to return the appropriate DragImageList in your definition of TTreeDashDragObject. This shouldn't involve overriding TAdvTreeView.