Solved

Drag & Drop from Listbox to Treeview

Posted on 2003-12-09
6
657 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
Technology Partners: 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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