Abandoning a drag and drop between listboxes

I use drag and drop to update a listbox from entries in another listbox. A user can select one or more rows from the sending listbox and drop them on the receiving listbox to make database updates. In the DragRow event of the sending listbox, I raise an event to set a flag for the receiving listbox to let it know it’s ok to accept a drop. This is because I only want the receiving listbox to accept drops from the sending listbox, not any text from any other field. When the drop is complete, the DropObject event of the receiving listbox clears the flag as it processes the drop. All is wonderful!

If the user abandons the drop, how do I clear the flag that tells the receiving listbox it’s ok to accept a drop? It’s too late to handle it in the DragRow event of the sending listbox because the drop doesn’t fire until that routine is exited. I can’t handle it in the receiving listbox DropObject event because the user abandoned the drag somewhere else. If I don’t clear the flag after an abandoned drag, then text from anywhere could be dropped on the receiving listbox and unpredictable result will occur.

Start a Timer that checks System.MouseDown. As soon as it is False, clear the flag and stop the timer.

I was looking for something sophisticated and complex. How disappointing… :slight_smile:

Thanks!

There is a more sophisticated way to do this. Instead of having your destination listbox accept text drops, have it accept raw data drops only using the Listbox.AcceptRawDataDrop method. Raw data can only be dragged within the application - your listbox won’t accept any drops that don’t contain the data type specified in the AcceptRawDataDrop call.

Maybe I have a misunderstanding on this, but I don’t think this will work for me. It appears to me that AcceptRawDataDrop is for limiting file types. I’m dragging an entry from one listbox to another. The entry is a database key field which is a string value. I think I need AcceptTextDrop.

The documentation is misleading; use any identification string you like, as long as it is the same between Listbox.AcceptRawDataDrop and the DragItem.

Let me clarify a point in my original response: raw data is only restricted to your application when it is added to the DragItem via the DragItem.PrivateRawData(type) method, as opposed to the DragItem.RawData(type) method.

[quote=42376:@Eric Williams]The documentation is misleading; use any identification string you like, as long as it is the same between Listbox.AcceptRawDataDrop and the DragItem.

[/quote]
Thanks! The documentation does require a bit of digging on this point. This way works a lot nicer as it won’t highlight the receiving listbox unless the dragitem matches. Doing it my way, the control would highlight regardless of the dragitem even if the drop would be rejected. I don’t have to bother checking whether or not the user abandoned the drop.

Good solution!