Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to Drag and Drop Items within TTreeView Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Drag and Drop Items within TTreeView 22-Jul-04
Category
VCL-General
Language
Delphi All Versions
Views
322
User Rating
8
# Votes
1
Replies
0
Publisher:
Savic, Igor
Reference URL:
			1   
2   unit Unit1; 
3   
4   interface 
5   
6   uses 
7     Windows, Messages, SysUtils, Variants, Classes, Controls, Forms, 
8     Dialogs, StdCtrls, ComCtrls; 
9   
10  type 
11    TForm1 = class(TForm) 
12      TreeView1: TTreeView; 
13      Label1: TLabel; 
14      procedure TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer); 
15      procedure TreeView1DragOver(Sender, Source: TObject; X, Y: Integer; 
16        State: TDragState; var Accept: Boolean); 
17    private 
18      { Private declarations } 
19      procedure MoveNode(TargetNode, SourceNode : TTreeNode); 
20    public 
21      { Public declarations } 
22    end; 
23  
24  var 
25    Form1: TForm1; 
26  
27  implementation 
28  
29  {$R *.dfm} 
30  
31  // 
32  // Procedure which will move node and its subnodes 
33  // 
34  procedure TForm1.MoveNode(TargetNode, SourceNode : TTreeNode); 
35  var 
36    nodeTmp : TTreeNode; 
37    i : Integer; 
38  begin 
39    with TreeView1 do 
40    begin 
41      nodeTmp := Items.AddChild(TargetNode,SourceNode.Text); 
42      for i := 0 to SourceNode.Count -1 do 
43      begin 
44        MoveNode(nodeTmp,SourceNode.Item[i]); 
45      end; 
46    end; 
47  end; 
48  
49  
50  procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer); 
51  var 
52    TargetNode, SourceNode : TTreeNode; 
53  begin 
54    with TreeView1 do 
55    begin 
56      TargetNode := GetNodeAt(X,Y); // Get target node 
57      SourceNode := Selected; 
58      if (TargetNode = nil) then 
59      begin 
60        EndDrag(False); 
61        Exit; 
62      end; 
63      MoveNode(TargetNode,SourceNode); 
64      SourceNode.Free; 
65    end; 
66  end; 
67  
68  procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer; 
69    State: TDragState; var Accept: Boolean); 
70  begin 
71    if (Sender = TreeView1) then // If TRUE than accept the draged item 
72    begin 
73      Accept := True; 
74    end; 
75  end; 
76  
77  end. 


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC