-1

My code is working and the drag and drop but what i want to add is to Drag and Drop items from ListBox1 to ListBox2 with their images. Also when i want to rearrange the items in ListBox2 it duplicates without deleting the previous one.

Or if it's possible I would love to know how to move items from ListBox1 to ListBox2 with just a double Click no need to the drag and drop.

I am using the 10.2 version

Here is my code and i would appreciate if anyone can help me :

type
  TListBoxItem = class(FMX.ListBox.TListBoxItem)

private
    function GetData: String;
    procedure SetData(const Value: String);

published
    property Data:String Read GetData Write SetData;
end;

var
  Form13: TForm13;


procedure TForm13.ListBox3DragDrop(Sender: TObject; const Data: TDragObject;
  const Point: TPointF);

var
  T,D:TListBoxItem;

Begin
  ListBox3.ItemHeight:=81;
  ListBox3.Canvas.Font.Size:=20;


  T:= TListBoxItem.Create(nil);
  D:= TListBoxItem(Data.Source);

  T.Data:= D.Data;
  ListBox3.AddObject(T);    

end;

procedure TForm13.ListBox3DragOver(Sender: TObject; const Data: TDragObject;
  const Point: TPointF; var Operation: TDragOperation);
begin

 if (Sender is TListBoxItem) and (Data.Source is TListBoxItem) and (Sender is TImage)
    and Not (Sender = Data.Source)
    and  (TListBoxItem(Data.Source).Text<>'')
    then Operation:=TDragOperation.Move
    else Operation:=TDragOperation.None;

end;

{ TListBoxItem }

function TListBoxItem.GetData: String;
begin
  Result := Text;
end;

procedure TListBoxItem.SetData(const Value: String);
begin
  Text:=Value;
end;
Samar
  • 3
  • 4
  • I added the `firemonkey` tag, based on the `TListboxItem` class declaration. Whenever your question concerns `firemonkey` framework, indicate it in the tags, Target platforms may be important to know and also which Delphi version you are using. The latter because of the intensive development that has taken place tha last years. – Tom Brunberg Apr 28 '17 at 09:14
  • okay thank you i will be more specified. this is the first time i post – Samar Apr 28 '17 at 09:44
  • It's ok, we have all had our first time, just pay attention to **all** requested details. I will take a lok at your issue, but I ask you to include in your post how you populate the first listbox. Also remove the obvious impossibilities in `OnDragOver` (Sender can not be a `TListBoxItem` and a `TImage` simultaneously!) – Tom Brunberg Apr 28 '17 at 10:01

1 Answers1

2

Put DblClick event on the listbox1, move the parent of the selected item to the other listbox.

procedure TForm1.ListBox1DblClick(Sender: TObject);
begin
  if ListBox1.Selected <> nil then
    ListBox1.Selected.Parent := ListBox2;
end;
Kohull
  • 674
  • 4
  • 10
  • @Samar If you think about it, I believe you understand why *...it's not working...* is one of the most useless sequence of words. So, please add a new comment and say exactly what is not working. – Tom Brunberg Apr 28 '17 at 09:08
  • @TomBrunberg okay so in my code am facing two problems i hope you can help me in any of it. First one when i drag and drop items (every item has text and an image) from listbox1 to listbox2 only the text gets moved. And the second problem is when i want to switch the places of the items in the listbox2 it gets duplicated. I just want items to switch without duplicating. – Samar Apr 28 '17 at 09:40
  • @Samar **Originally** you asked for d&d **OR** doubleclick moving item from LB1 to LB2 (There was nothing about rearranging items in LB2). You can not suddenly change your question to a different one. IOW you asked for 1 of 2 options and Kohull answered to your second option. My simple test shows it works correctly. The answer is correct, unless you can explain how it doesn't answer neither of the two options you originally asked for. – Tom Brunberg Apr 28 '17 at 10:13
  • Thank you @TomBrunberg i already removed the image call. I tried the DblClick it didn't work for me still the drag and drop only works with the text. And I didn't change my questions it's just that i have 2 problems and i'm trying to find a solution and in the question you will find the rearrange items. and in my question i said if there isn't a possibility to do that is it possible to do that with the double click. in all cases thnx – Samar Apr 28 '17 at 10:18
  • @Samar This is copied from your original yesterday question, and the text is still the same: *Or if it's possible I would love to know how to move items from ListBox1 to ListBox2 with just a double Click no need to the drag and drop.* That is exactly what Kohull answered! – Tom Brunberg Apr 28 '17 at 10:28
  • and all what i said to him that it didn't work for me :) – Samar Apr 28 '17 at 11:02