Nếu bạn đang nhận dữ liệu thông qua GetNodeData hơn kéo và thả của bạn có thể được thực hiện như thế này:
uses
ActiveX;
Gán sự kiện kéo đến cây:
OnDragAllowed:
procedure TForm1.vt1DragAllowed(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex;
var Allowed: Boolean);
begin
Allowed := True;
end;
OnDragOver:
procedure TForm1.vt1DragOver(Sender: TBaseVirtualTree; Source: TObject; Shift: TShiftState;
State: TDragState; Pt: TPoint; Mode: TDropMode; var Effect: Integer; var Accept: Boolean);
begin
Accept := (Source = Sender);
end;
OnDragDrop:
procedure TForm1.vt1DragDrop(Sender: TBaseVirtualTree; Source: TObject; DataObject: IDataObject;
Formats: TFormatArray; Shift: TShiftState; Pt: TPoint; var Effect: Integer; Mode: TDropMode);
var
pSource, pTarget: PVirtualNode;
attMode: TVTNodeAttachMode;
begin
pSource := TVirtualStringTree(Source).FocusedNode;
pTarget := Sender.DropTargetNode;
case Mode of
dmNowhere: attMode := amNoWhere;
dmAbove: attMode := amInsertBefore;
dmOnNode, dmBelow: attMode := amInsertAfter;
end;
Sender.MoveTo(pSource, pTarget, attMode, False);
end;
Cũng đừng quên đặt toAutoDeleteMoveNodes
False trong TreeOptions.AutoOptions
.
Nó phụ thuộc vào cách bạn đã xây dựng cây của bạn. Cung cấp thêm thông tin về điều đó. – Linas
Mọi thứ được lưu trữ trong Dữ liệu của PVirtualNode, nếu đó là ý của bạn? Nó giống như một listview thực sự. – Jeff