I have a ListBox that I need to contain list of files. I need functionality for user to select one or multiple files and than to drag files and drop them on the ListBox. When files are dropped, Items are created with a file names. This works fine, but the problem is, when I drag over and drop file on a dynamically created Item inside ListBox, file icon remains drawn on a desktop as a "ghost". Please check following screenshots for more details:
This "sample.txt" icon remains on desktop. Can anyone tell me what am I doing wrong?
This is the code used for drag and drop operation:
procedure TTestForm.FileListBoxDragDrop(Sender: TObject; const Data: TDragObject;
const Point: TPointF);
var
i: integer;
item: TListBoxItem;
begin
try
FileListBox.BeginUpdate;
for i := Low(Data.Files) to High(Data.Files) do begin
Item := TListBoxItem.Create(Self);
Item.Text := ExtractFileName(Data.Files[i]);
Item.Parent := FileListBox;
end;
finally
FileListBox.EndUpdate;
end;
end;
procedure TTestForm.FileListBoxDragOver(Sender: TObject; const Data: TDragObject;
const Point: TPointF; var Accept: Boolean);
begin
Accept := True;
end;