DropObject event triggered when drag-reordering listbox rows

I have a listbox and I wonder why the DropObject event is triggered when I drag-reorder a row. Is there a possibility to avoid that? I tried for hours but I am unable to come up with a working solution. My DropObject event has lot of code I don’t want to be ran when the user is simply reordering rows.

Thanks,
Stan

add a special dragitem rawdata when you drag an item into your listbox.
if that rawdata is not present, then simply don’t execute the code of the dropobject.

A sample project showing what you are doing would be very helpful. There are just too many variables for one to guess based on the info you’ve provided.

I can’t use a dragitem raw data since I don’t know if the user will drag to the same listbox or to somewhere else.

This is a sample project: https://www.maxprog.com/misc/xojo/Drag-Reorder_firing_DropObject_event.zip

I understand that you are creating the dragitem, so no matter if the drag goes to your listbox, or somewhere else, you can add one more rawdata (private or not) and you will catch this rawdata to not run your drop code. this raw data will simply be ignored if the drag goes to another app.

If I do that, when dragging from that listbox to another one, it will stop working. How do you differentiate dragging inside the same listbox and to another listbox?

You need to handle drag-reorder yourself.

Drag-reorder works perfect as is, I just want it not to trigger the DropObject event or at least a trick I can use to know that the user is Drag-reordering rows, that way I can avoid given code to be executed. The sample code I have posted is quite clear (I believe) about what is happening.

What about setting a boolean property “bReorder” to true in the DragReorderRows event. Then test for that in the DropObject event? Not sure if that will cover all your bases but it will prevent the DropObject code from running when reordering rows.

example

Put a break statement in the DropObject event and look at the obj object in the debugger. You’ll notice that it’s a relatively incomplete DragItem object. I bet you could figure out from that whether you need to deal with it or not.

[quote=334651:@Peter Fargo]What about setting a boolean property “bReorder” to true in the DragReorderRows event. Then test for that in the DropObject event? Not sure if that will cover all your bases but it will prevent the DropObject code from running when reordering rows.

example[/quote]
That may not work consistently. DragReorderRows is not guaranteed to fire before DropObject.

One thing you could do though, is modify the DragItem in the DragRow event. For instance, as was suggested above, you could add some data to the dragitem in the DragRow event that only you care about, heck, it could be just be a datatype with just a space in it.

drag.PrivateRawData("xxxx") = " "

and then in the DropObject event just check…

if obj.PrivateRawData("xxxx") = " " then return end if

Good to know.