Solved

Drag & Drop from Listbox to Treeview

Posted on 2003-12-09
6
662 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month10 days, 13 hours left to enroll

628 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