Drag Drop ListBoxItems from ListBox1 to ListBox2 with their images and avoiding duplication Delphi

烈酒焚心 提交于 2019-12-13 09:13:24

问题


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;

回答1:


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;


来源:https://stackoverflow.com/questions/43635461/drag-drop-listboxitems-from-listbox1-to-listbox2-with-their-images-and-avoiding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!