Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Drag & drop from 1 listbox to another

Status
Not open for further replies.

LucieLastic

Programmer
May 9, 2001
1,694
GB
hi

Could someone tell me how to get the receiving listbox to display the string that's been dragged from the source listbox.

I've set up the following but don't know what to put in the DrapDrop event:-

procedure TFormMain.lbColumnsDragOver(Sender, Source: TObject; X,
Y: Integer; State: TDragState; var Accept: Boolean);
begin
Accept := Source is TListBox;
end;

procedure TFormMain.lbselectedColsDragDrop(Sender, Source: TObject; X,
Y: Integer);
begin
if (Sender is TListBox) and (Source is TListBox) then //think the (Source is ...) bit is wrong too.
begin
with Sender as TListBox do
begin
//Don't know what to put here

end;
end;
end;


Many thanks for any help.

lou
 
How about something like this:
Code:
procedure TForm1.ListBox2DragDrop(Sender, Source: TObject; X, Y: Integer);
begin
  if Source is TListBox then
  begin
    if(TListBox(Source).ItemIndex <> -1)then
     TListBox(Sender).Items.Add(TListBox(Source).Items[TListBox(Source).ItemIndex]);
  end;
end;

--- markus
 
Those two event handlers should both be assigned to the target listbox.
 
McMerfy, thanks for that, will try it.

Mike, yes, they are. I have 2 sets so they can drag drop to and from each other - I happen to have copied 1 event from each - sorry for the confusion.
 
When thinking about drag/drop, I find that it helps to think of the Source as the source, and the Sender as the target of the drag/drop operation. I even add a comment to this effect to my drag/drop routines, to remind myself. -- Doug Burbidge mailto:dougburbidge@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top