線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1334
推到 Plurk!
推到 Facebook!

如何將TreeView內的資料拖曳到 另一個TreeView

尚未結案
T.J.B
版主


發表:29
回覆:532
積分:497
註冊:2002-08-14

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-07-08 00:37:12 IP:218.160.xxx.xxx 未訂閱
我要如何將TreeView內的資料拖曳到 另一個TreeView 用onDragdrop事件一直試不出來 是否還有別的事件要搭配 可否請各位指點一下 謝謝 天行健 君子當自強不息~~@.@
------
天行健
君子當自強不息~~@.@
qoo1234
版主


發表:256
回覆:1167
積分:659
註冊:2003-02-24

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-07-08 02:08:41 IP:218.163.xxx.xxx 未訂閱
 
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-07-08 02:11:11 IP:218.163.xxx.xxx 未訂閱
依需要自行修改
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

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-07-08 11:55:54 IP:218.80.xxx.xxx 未訂閱
用TreeView1.Assign(TreeView2)就可以了
T.J.B
版主


發表:29
回覆:532
積分:497
註冊:2002-08-14

發送簡訊給我
#5 引用回覆 回覆 發表時間:2004-07-09 16:40:26 IP:61.218.xxx.xxx 未訂閱
謝謝兩位的幫助 已經完成了 天行健 君子當自強不息~~@.@
------
天行健
君子當自強不息~~@.@
系統時間:2024-11-25 2:25:02
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!