I’m having problems with a DragItem, generated with Listbox.DragRow, on Mac 10.14, when I generate multiple rows for the purpose of displaying pictures for each row, as is common with Mac.
The problem is that every rowpicture displayed by the Mac shows only the last picture I create. Every row looks the same.
I do this (code shortened) in Listbox.DragRow:
d.DragPicture = P(0)
For i = 0 To numRows - 1
d.AddItem(0, 0, 20, 20)
// now the current row is the new one added, as far as I understand it
d.DragPicture = P(i + 1)
Next
How do I get every row to display a different graphic; P(0…)?
You have to create one large picture and then pad it out.
Use me.selcount and me.rowheight to calculate the height of the final image. Then use me.trueWindow.bitmapForCaching to create the correct DPI version of the image.
Then either the documentation is wrong, or it’s a bug. From the DragItem entry:
“Alternatively you can not provide the picture in the constructor and then set the DragPicture property for each [item] 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.”
I know. I did this in 10.14. My code does what Sam suggested, making one picture and adding it at the end. As Jason said, doing it normally just has the same picture for every Item in the DragItem. Bug.
It seems I had made some assumptions that caused this confusion and for that I apologize.
In the situations where I had faced a similar problem, my complete solution was to combine everything into a single drag item. This may not actually apply in your situation, as it depends on the end result of the drag.
When I modified your code to closer match my solution, the image does at least look right. But all the drag contents are now in a single item. If you can modify your dropObject event to parse them out, then this will work. Otherwise if you need each item to be separate, you may be out of luck until Xojo fix the problem.
Dim i As Integer
Dim numRows, DragPicHeight As Integer
DIm P As Picture
numRows = Me.SelCount
DragPicHeight = numRows * Me.RowHeight
P = Me.TrueWindow.bitmapForCaching(Me.Width, DragPicHeight)
For i = 0 To numRows - 1
DrawToDragPic(P, Me, i)
Next
Dim rows() as string
Dim n as integer = me.listcount -1
For l as integer = 0 to n
if me.selected( l ) then rows.append me.cell( l, 0 )
Next
drag.text = join( rows, endofLine )
drag.dragPicture = p
return True
So abandon AddItem for the time being… But if I’m dragging (say) 4-5 FolderItems, I need separate Items in the DragItem. That can be hacked around, however the other problem it invokes is that I have to give up the nice NUMBER graphic the Mac introduces of the amount of items being dragged. Unless (I haven’t tried this yet) on a single item a number doesn’t appear.