Solved

Drag & Drop from Listbox to Treeview

Posted on 2003-12-09
6
659 Views
Last Modified: 2010-05-18
Hi,

I need some help / code / examples to drag and drop a value from a Listbox to a treeview. The value from the listbox should will always create a node (with the value of the listbox item) underneath the node that it is dropped on.

Regards

Pierre
0
Comment
Question by:barnarp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 9904349
a sample

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    ListBox1: TListBox;  //dragmode is set to dmAutomatic
    TreeView1: TTreeView;
    procedure TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}


procedure TForm1.TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  accept := source = listbox1;
end;

procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
var ANode : TTreeNode;
begin
  ANode := TreeView1.GetNodeAt(x,y);
  TreeView1.Items.Add(ANode,ListBox1.Items[Listbox1.ItemIndex]);
  //or if meant as Child (just uncomment)
  //TreeView1.Items.AddChild(ANode,ListBox1.Items[Listbox1.ItemIndex]);

  //if wanted to delete the listboxentry (just uncomment)
  //ListBox1.Items.Delete(Listbox1.ItemIndex);
end;

end.

meikl ;-)
0
 

Author Comment

by:barnarp
ID: 9912006
thanks, wil check it out
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9912019
take your time ;-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:barnarp
ID: 9912146
100% thanks alot.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9912166
if it works for you,
don't forget the grade
-> just press the accept-button near the comment, which helps you most

otherwise reask/comment for clarification

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9912243
thanks, glad to helped you :-)

meikl ;-)
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question