Solved

Drag & Drop from Listbox to Treeview

Posted on 2003-12-09
6
648 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now