8
votes

I have implemented drag and drop in a ListView in my WPF application. Items can be dragged and dropped inside the ListView, and also into a TreeView that is beside the ListView.

Currently, I have it set up so that when you drag to the bottom of the ListView, it automatically scrolls down the list.

What I'd like to know is if there's any way to be able to scroll through the ListView with the mouse wheel while I'm dragging its items? It seems like the mouse wheel events aren't being fired while I'm dragging.

1
You want to use the mouse wheel and the left mouse button at the same time? Geez, I'm not nearly that coordinated.Robert Harvey
Just wondering: Who would ever use that? Enough people have problems with drag and drop already, scrolling simultaneously doesn't sound much easier to perform.Joey
I would use it, and apparently we absolutely need it to happen. What type of drag-and-drop problems are you talking about?Robin
To start, I recommend using Spy++ to watch mouse events flowing through the WMQ when you are attempting to perform this action. Confirm scrolling generates messages while a drag is in progress. Seeing the messages will better prepare you for handling them using interop.Ed Noepel
Usually in any application you scroll by moving the entry while dragging at the border of the list. e.g. Scroll down, when the item is at the very bottom of the list. I think this is what most users are used to.Daniel Bişar

1 Answers

0
votes
  1. create (and start) mouse hook helper before DragDrop.DoDragDrop(...)
  2. analyze mouse wheel (+ check if mouse over control)
  3. stop (dispose) mouse hook helper after DoDragDrop() operation

Note: always stop mouse hook helper, because it can freeze application when it dispose on Window close (I see it on XP).

here you can find one MouseHook, adopt it (I found bug:)) or something like it.