【发布时间】:2017-04-26 13:19:41
【问题描述】:
我的代码正在运行并且可以拖放,但我要添加的是使用它们的图像将项目从 ListBox1 拖放到 ListBox2。此外,当我想重新排列 ListBox2 中的项目时,它会重复而不删除前一个。
或者,如果可能的话,我很想知道如何通过双击将项目从 ListBox1 移动到 ListBox2,而无需拖放。
我用的是10.2版本
这是我的代码,如果有人可以帮助我,我将不胜感激:
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;
【问题讨论】:
-
我添加了
firemonkey标签,基于TListboxItem类声明。每当您的问题涉及firemonkey框架时,请在标签中注明,了解目标平台以及您使用的 Delphi 版本可能很重要。后者是因为过去几年的密集发展。 -
好的,谢谢,我会更详细。这是我第一次发帖
-
没关系,我们都是第一次,请注意所有要求的细节。我会看看你的问题,但我要求你在你的帖子中包括你如何填充第一个列表框。同时删除
OnDragOver中明显的不可能(发件人不能同时是TListBoxItem和TImage!)
标签: delphi drag-and-drop listbox firemonkey listboxitem