Drag and drop!!!


how can i drap and drop between Treeview and Listbox

1. from treeview to listbox

many thanx
karen021897Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
hi,
i have to mention these components(someone else would otherwise for sure  :-):

http://www.melander.dk/delphi/dragdrop/

Regards Barry
0
hubdogCommented:
Here is  a demo . I think perhaps you  should change it to match your demand.
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    ListBox1: TListBox;
    TreeView1: TTreeView;
    procedure TreeView1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
    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
  if (source is TListBox) and (Treeview1.GetNodeAt(x,y)<>nil) then
      accept:=true;
end;

procedure TForm1.ListBox1DragOver(Sender, Source: TObject; X, Y: Integer;
  State: TDragState; var Accept: Boolean);
begin
  if Source is TTreeView then
    Accept:=true;
end;

procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  aPoint:TPoint;
begin
  APoint.x:=x;
  APoint.Y:=y;
  if listbox1.ItemAtPos(apoint,true)<>-1 then
    listbox1.begindrag(false);
end;

procedure TForm1.TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  APoint:TPoint;
begin
  APoint.x:=x;
  APoint.y:=y;
  if treeview1.GetNodeAt(x,y)<>nil then
    Treeview1.begindrag(false);
end;

procedure TForm1.ListBox1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
  aPoint:TPoint;
begin
  aPoint.x:=x;
  aPoint.y:=y;
  if Listbox1.ItemAtPos(APoint,true)=-1 then
    ListBox1.Items.Add(TreeView1.selected.Text)
  else
    listbox1.items.Insert(listbox1.itematpos(aPoint,true),Treeview1.selected.text);
  Treeview1.selected.Delete;
end;

procedure TForm1.TreeView1DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  Treeview1.Items.Insert(TreeView1.selected,Listbox1.Items.strings[Listbox1.itemIndex]);
  Listbox1.Items.Delete(Listbox1.ItemIndex);
end;

end.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
karen021897Author Commented:
thanks for that,
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.