please I need a help how to proper work with TreeView when the DragMode is set to dmAutomatic. In this case I cannot expand the nodes by click to plus sign (+), the mouse event are not triggered (MouseDown nor NodeClick).
What I need is drag node and drop into button and show node's caption onto Button's. I was not sucessfull with "interaction - dragMode" property, so please could you help me how to handle this situation?
When I set DragMode = dmAutomatic, I can handle drag'n'drop events and everithig is fine, but the TreeView is not working (selecting, expanding)
When I set DragMode = dmManual, the TreeView behaviour is fine, but drag'n'drop is not working.
A complete sample can be found here, and involves assigning events to the custom drag/drop events:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, AdvCustomControl, AdvTreeViewBase,
AdvTreeViewData, AdvCustomTreeView, AdvTreeView, Types;
type
TForm1 = class(TForm)
AdvTreeView1: TAdvTreeView;
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure DoCustomDragOver(Sender: TObject; Source: TObject; Point: TPointF; var Accept: Boolean);
procedure DoCustomDragDrop(Sender: TObject; Source: TObject; Point: TPointF);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.DoCustomDragDrop(Sender, Source: TObject; Point: TPointF);
var
n: TAdvTreeViewVirtualNode;
begin
if Source is TAdvTreeView then
begin
n := (Sender as TAdvTreeView).XYToNode(Point.X, Point.Y);
if Assigned(n) and Assigned(n.node) and
Assigned((Source as TAdvTreeView).DragNode) and Assigned((Source as TAdvTreeView).DragNode.Node) then
begin
n.Node.Nodes.Add.Assign((Source as TAdvTreeView).DragNode.Node);
end;
end;
end;
procedure TForm1.DoCustomDragOver(Sender, Source: TObject; Point: TPointF;
var Accept: Boolean);
begin
Accept := Source is TAdvTreeView;
end;
procedure TForm18.FormCreate(Sender: TObject);
begin
AdvTreeView1.Interaction.DragDropMode := tdmCopy;
AdvTreeView1.OnCustomDragOver := DoCustomDragOver;
AdvTreeView1.OnCustomDragDrop := DoCustomDragDrop;
end;
end.
This can be achieved by selecting the node in the mousedown event:
procedure TForm18.AdvTreeView1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
n: TAdvTreeViewVirtualNode;
begin
n := AdvTreeView1.XYToNode(X, Y);
if Assigned(n) then
AdvTreeView1.SelectNode(n.Node);
end;