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

Drag from ListBox to Edit

By , About.com Guide

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

Explore Delphi Programming
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. 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.