Drag from ListBox to Edit

106 29
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

Source...
Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time

Leave A Reply

Your email address will not be published.