type TForm1=class(TForm) TreeView1:TTreeView; ListView1:TListView; procedureTreeView1DragOver(Sender,Source:TObject;X,Y:Integer; State:TDragState;varAccept:Boolean); procedureTreeView1DragDrop(Sender,Source:TObject;X,Y:Integer); private { Private declarations } public { Public declarations } end;
var Form1:TForm1;
implementation
{$R *.dfm}
procedureTForm1.TreeView1DragOver(Sender,Source:TObject;X,Y:Integer; State:TDragState;varAccept:Boolean); begin Accept:=False; if(sourceisTTreeView)or(sourceisTListView)then Accept:=True; end;
procedureTForm1.TreeView1DragDrop(Sender,Source:TObject;X,Y:Integer); var tSrcNode,tDesNode:TTreeNode; begin tDesNode:=TTreeView(Sender).GetNodeAt(X,Y); ifSourceisTTreeViewthen begin tSrcNode:=TTreeView(Sender).Selected; tSrcNode.MoveTo(tDesNode,naAddChild); end;
ifSourceisTListViewthen begin TreeView1.Items.AddChild(tDesNode,ListView1.Selected.Caption); ListView1.Selected.Delete; TreeView1.Selected.Expand(True); end; end;