将具有其图像的ListBoxItems从ListBox1拖放到ListBox2,并避免重复Delphi [英] Drag Drop ListBoxItems from ListBox1 to ListBox2 with their images and avoiding duplication Delphi

查看:174
本文介绍了将具有其图像的ListBoxItems从ListBox1拖放到ListBox2,并避免重复Delphi的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码正在工作,并且拖放,但是我想添加的内容是将ListBox1中的项目及其图像拖放到ListBox2中.另外,当我想重新排列ListBox2中的项目时,它会重复而不删除上一个项目.

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.

或者,如果可能的话,我很想知道如何通过双击将项目从ListBox1移至ListBox2.

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.

我正在使用10.2版本

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;

推荐答案

将DblClick事件放在列表框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;

这篇关于将具有其图像的ListBoxItems从ListBox1拖放到ListBox2,并避免重复Delphi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆