如何將TreeView內的資料拖曳到 另一個TreeView |
尚未結案
|
T.J.B
版主 發表:29 回覆:532 積分:497 註冊:2002-08-14 發送簡訊給我 |
|
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
Here is an example of using OnDragOver and OnDragDrop events: procedure TForm1.TreeViewDragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); var SourceNode, TargetNode: TTreeNode; SourceView, TargetView: TTreeView; begin SourceView:=Source as TTreeView; SourceNode:=SourceView.Selected; TargetView:=Sender as TTreeView; TargetNode:=TargetView.GetNodeAt(X,Y); // scrolling of the target view if y<20 then SendMessage(TargetView.Handle,WM_VSCROLL,SB_LINEUP,0); if y>TargetView.Height-20 then SendMessage(TargetView.Handle,WM_VSCROLL,SB_LINEDOWN,0); // accept:=here you'll set any condition you need end; procedure TForm1.TreeViewDragDrop(Sender, Source: TObject; X, Y: Integer); var SourceNode, TargetNode: TTreeNode; SourceView, TargetView: TTreeView; begin SourceView:=Source as TTreeView; SourceNode:=SourceView.Selected; TargetView:=Sender as TTreeView; TargetNode:=TargetView.GetNodeAt(X,Y); SourceView.Items.BeginUpdate; // copying ... SourceView.Items.EndUpdate; end; |
qoo1234
版主 發表:256 回覆:1167 積分:659 註冊:2003-02-24 發送簡訊給我 |
依需要自行修改
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ComCtrls; type TForm1 = class(TForm) TreeView1: TTreeView; TreeView2: TTreeView; procedure FormCreate(Sender: TObject); procedure TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer); procedure TreeView2DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); private { Private declarations } public { Public declarations } end; var Form1: TForm1; FDest, FSource: TTreeNode; implementation {$R *.dfm} function NodeCopy(TreeView: TTreeView; Dest, Source: TTreeNode): TTreeNode; var i : Integer; aNode : TTreeNode; begin Result := Dest; aNode := TreeView.Items.AddChild(Dest, ''); aNode.Assign(Source); for i := 0 to Source.Count - 1 do NodeCopy(TreeView, aNode, Source.Item[i]); end; procedure MoveNode(TreeView: TTreeView; Dest, Source: TTreeNode); begin NodeCopy(TreeView, Dest, Source); Source.Free; end; procedure TForm1.FormCreate(Sender: TObject); begin Treeview1.DragMode:=dmAutomatic; Treeview2.DragMode:=dmAutomatic; end; procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer); begin FSource:=TreeView1.Selected; FDest:=TreeView2.GetNodeAt(X,Y); if y<20 then SendMessage(TreeView2.Handle,WM_VSCROLL,SB_LINEUP,0); if y>TreeView2.Height-20 then SendMessage(TreeView2.Handle,WM_VSCROLL,SB_LINEDOWN,0); end; procedure TForm1.TreeView2DragOver(Sender, Source: TObject; X, Y: Integer; State: TDragState; var Accept: Boolean); begin FSource:=TreeView1.Selected; FDest:=TreeView2.GetNodeAt(X,Y); if (FDest<> nil)and (FSource<> nil) then MoveNode(TreeView1,FDest,FSource); // Copy TreeView1.Items.EndUpdate; end; end. |
sl@cableplus.com.cn
高階會員 發表:168 回覆:359 積分:130 註冊:2004-03-26 發送簡訊給我 |
|
T.J.B
版主 發表:29 回覆:532 積分:497 註冊:2002-08-14 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |