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 items from a TTreeView onto a TListBox 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
31-Jan-03
Category
VCL-General
Language
Delphi 2.x
Views
132
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Tomas Rutkauskas

I have a treeview which I need to be able to drag items from onto a listbox (they 
have to be deleted from the treeview when moved, of course). I have been able to do 
this between two listboxes, but this one eludes me. Can anyone get me started 
please?

Answer:
1   
2   procedure TForm1.TreeView1MouseDown(Sender: TObject; Button:
3     TMouseButton; Shift: TShiftState; X, Y: Integer);
4   begin
5     if TreeView1.Items.Count = 0 then
6       exit;
7     if Button = mbLeft then
8       TreeView1.BeginDrag(False); {begin drag}
9   end;
10  
11  procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y:
12    Integer; State: TDragState; var Accept: Boolean);
13  begin
14    Accept := (Sender = TreeView1);
15  end;
16  
17  procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
18  var
19    dx: integer;
20    Node: TTreeNode;
21  begin
22    if Source = TreeView1 then
23    begin
24      Node := TreeView1.Selected;
25      if Node <> nil then
26      begin
27        with TListBox(Sender) do
28        begin
29          dx := ItemAtPos(Point(X, Y), false);
30          Items.Insert(dx, Node.Text);
31          {or use:
32          Items.InsertObject(dx, Node.Text, Pointer(Node.Data)); }
33        end;
34        Node.Delete;
35      end;
36    end;
37  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