Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

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

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;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...