Solved

Drag & Drop from Listbox to Treeview

Posted on 2003-12-09
6
651 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
  • 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
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Multiple image collision 13 75
Base1 Encode/Decode 3 77
Delphi and Access based Enumeration 9 64
Not able to call Delphi XE10 dll function from Delphi 6.0 4 28
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…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

821 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