I’ve been working on this for days and keep coming up empty. I’m trying to do something very simple: A ListBox full of FolderItems that can be dragged to the Finder in macOS to move the files there.
The dragging and file manipulation works great. Where it all breaks down is the DragPicture. For each selected row in the ListBox, I use Drag.AddItem and assign the FolderItem and picture.
When I only drag one row, the drag picture looks great. When I drag two or more rows, I get an overlay of diagonal text, along with my original DragPicture, and it looks super strange.
I’ve researched and tried numerous things to get rid of the diagonal text items in the DragPicture — they’re obviously put there automatically by Xojo. How do I get rid of those?
Here’s a screenshot showing the issue: Dropbox - dragpicture.png - Simplify your life
Any help would be most appreciated!
Is there any way to prevent Xojo from drawing and applying it’s own DragPicture to your DragItem when you’ve used DragItem.AddItem?
I think that this was discussed before. But I don’t remember the solution. It was something with the way dragitems are created.
Aaahhhh… I was testing drag-and-drop and now I made my app crash hard.
Interesting. For one listbox I get the good drag-image and for another listbox I get the wishy-washy one:
And the second one makes a hard crash.
That’s interesting. What is the difference in the ListBoxes? My app never crashes.
I saw one other thread about this and the solution was to not use AddItem and instead store the multiple rows in some kind of NthField string design or other object reference. I cannot do that as far as I know, because I need true multiple FolderItem references to be able to drag out of the app and into Finder.
Can’t you share a sample project for testings ?
I’m using an NSTableView from the MBS plugin. I now get the crash in the debugger:
And yes, you need multiple folderitems.
The docs says:
Sharing an example will allow to know that and to check / provide guess or the answer.
Years ago, I’ve done One to Many Rows drag to Finder, but in one text file. I do not had the idea to test doing so in one file per row.
MacBook Pro M1
Big Sur 11.6 (Monterey when available)
Displaying Drag Pictures When There Are Multiple Drag Items
When there are multiple items in the DragItem, You can provide the drag picture in two ways: Using the constructor or by using the DragItem property.
If you use the constructor to provide a single picture, then on MacOS, this picture will be 3D stacked to indicate that there are multiple items. Since the same picture will be stacked in this manner it should be somewhat generic.
Alternatively you can not provide the picture in the constructor and then set the DragPicture property for each DragItem you add with AddItem. On MacOS this results in these separate images being vertically stacked to indicate each item being dragged. This can be more useful if your individual drag items are unique or distinct.
Could someone on a newer Monterey beta test the Xojo example “DragToFinder”?
#Pragma unused X
#Pragma unused Y
Var di As DragItem
Var f As FolderItem
Var d As DateTime
Var tos As TextoutputStream
d = DateTime.Now
f = SpecialFolder.Temporary.Child(“test” + Format(d.SecondsFrom1970, “#”))
If f <> Nil Then
tos = TextOutputStream.Create(f)
tos.Write(“Howdy! Created by Xojo DragToFinder example.”)
di = New DragItem(Self, 0, 0, 100, 100)
di.FolderItem = f
di.AddItem(0, 0, 100, 100) <------- this line added
If di.Destination <> Nil Then
If di.Destination IsA FolderItem Then
MessageBox(“Unable to get FolderItem for temporary file.”)
I’ve only added one line with di.AddItem. The example then makes a crash like the above screenshot.
No drag when running Big Sur 11.6 (20G165).
Sorry no Monterey here until it will be released.
Nota: the drag file does not have an extension. The example needs a modification.
Also: I never was able to delete the temporary file in code. So, at reboot, I clear the trash by hand (Cmd-Shift-Delete).
This is exactly what I’m doing, but I still get the diagonal overlapping duplicated text. I’m setting the property manually and not using the constructor.
Can anyone else get this to actually work and provide sample code?
This doesn’t work for me either on Big Sur or Monterey RC.
What is “doesn’t work” for you?
It just doesn’t do anything, I don’t get a drag to fire. I put the code into the MouseDrag event of a window.
Might want to look into this bug report:
59035 - Dragitem AddItem with and without DragPicture
Thanks — so this is a known bug then? And it looks like for almost two years (with no updates in over a year). That’s not encouraging. I can’t be the only person wanting to drag multiple items without an insane DragPicture. Do we have any hope that this will be resolved in the near future?
FYI, behavior depends both on IDE and macOS version.
Using 2019R1.1 with Big Sur, if you have more than one drag item the event just silently ends, which gives really bizarre behavior. See Crash an application on NSException - #26 by Mike_D for gory details.
How did you fix the crash?