I have two listboxes in the same window and I’m trying to drag and drop an entry from one to the other. The sending listbox entries can be reordered, so EnableDragReorder is set to true for that listbox.
When I try to drag an entry to the receiving listbox, the text in the dragitem is empty. I have set AcceptTextDrop to true and the visual cues for the drop work, but nothing is there to process.
If I turn set EnableDragReorder to false in the sending listbox, then the same drop works fine with the expected text being processed.
If I do the same drag from the receiving listbox to another listbox in a different window, the drop works fine regardless if EnableDragReorder is true or false.
Is this the way things should work? Am I missing something?
Can you post a project or some code? I can’t reproduce this.
I’ve created a project to demonstrate this and I’ve added it to my Dropbox. Find it here: https://www.dropbox.com/s/75jdp246ft2g1xb/DragReorderTest.xojo_binary_project?dl=0
Thanks, I see it now, but for me it also doesn’t work dragging to another window.
Anyways, the issue is a confluence of how you load up the drag parameter and how it’s read in DropObject.
When the drag parameter is passed to DragRow it already has an ‘item’. To this first item you can set Text, Picture, Folderitem, etc, but the way your loop works this first item is skipped and a second item is added and it’s Text set. Then in DropObject “if obj.TextAvailable then” is false because that first item never had it’s Text set.
There’s several ways to rectify this. Depends what you ultimately want to do. In the project lbSend is Single Selection. If that’s going to be the case you don’t need a loop building drag, just set it’s Text.
Function DragRow(drag As DragItem, row As Integer) As Boolean
drag.Text = me.Cell(row, 0)
If lbSend is going to be Multiple Selection then modify the DragRow loop so the initial item gets set and/or modify the DropObject loop so it doesn’t bail on an empty first item.
Sub DropObject(obj As DragItem, action As Integer)
if obj.TextAvailable then
loop until not obj.NextItem
Thanks so much for opening my eyes. Don’t know why EnableDragReorder was effecting this, but I guess that’s a feature, not a bug!
You were also correct regarding the drag to a different window. The different window was working in my real project for an unrelated reason that I missed.