0
votes

I have a listbox with items in it.

I need to re-arrange items within the same listbox with the mouse.

AllowDrag is set to true.

DragMode is dmManual.

Hittest is true.

It works only when you first select the item by clicking and then releasing the left mouse button, and then click the same item and drag/drop.

I searched in google, and saw somebody else has the same issue, and did not find a solution.

How can I establish a drag/drop within the same firemonkey listbox?

1

1 Answers

0
votes

I do it with the MouseDown event and the help of the unit FMX.Platform.

procedure TForm2.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Single);
var
   doData: TDragObject;
   Svc   : IFMXDragDropService;
   Img   : TBitmap;
begin
   if Assigned(ListBox1.ItemByPoint(X, Y)) and TPlatformServices.Current.SupportsPlatformService(IFMXDragDropService, Svc) then
   begin
      doData.Source := ListBox1.ItemByPoint(X, Y);
      Img           := ListBox1.ItemByPoint(X, Y).MakeScreenshot;
      Svc.BeginDragDrop(Self, doData, Img);
   end;
end;