问题
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