1. Home
  2. Computing & Technology
  3. Delphi Programming

Drag from ListBox to Edit

By Zarko Gajic, About.com

Here's how to drag an (string) item from a ListBox to an Edit control:

~~~~~~~~~~~~~~~~~~~~~~~~~
{
Set ListBox.DragMode = dmAutomatic
from the Object Inspector.

Let the OnDragOver and OnDragDrop
for the Edit control look like:
}

procedure TForm1.Edit1DragOver
  (Sender, Source: TObject;
  X,Y: Integer; State:TDragState;
  var Accept: Boolean) ;
begin
  Accept := True;
end;

procedure TForm1.Edit1DragDrop
  (Sender, Source: TObject; X,Y: Integer) ;
begin
  (Sender as TEdit).Text :=
    (Source as TListBox).Items
    [(Source as TListBox).ItemIndex]
end;

~~~~~~~~~~~~~~~~~~~~~~~~~
Here are some more dragging and dropping related articles.

Delphi tips navigator:
» Hide another application
« Associate an application with a file extension

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Using VCL Components
  5. TListBox
  6. Drag from ListBox to Edit

©2009 About.com, a part of The New York Times Company.

All rights reserved.