View Full Version : ListView - Selecting items by clicking and dragging the mouse
11 Sep 2009, 6:10 PM
Has anyone tried to mimic the Windows Explorer mouse click and drag effect on a ListView? i.e. when you are in Windows Explorer and are viewing the contents of a folder in thumbnail view, you can click the mouse and drag over the items you wish to select, in order to select them. In vista you get a blue box appearing over the area you are highlighting with you mouse.
Has anyone done this? Or can think of a starting point for me because I am lost for words :)
14 Sep 2009, 8:27 AM
I have not done this personally (in my application this wouldn't make too much sense at the moment).
Could you not add a MouseListener to your ListView and when you detect a selection (via a selectionListener) toggle on a "add to selection" flag and then add subsequent entries to the selection list? The selectionModel has a "select( )" series of methods which allow you to select items. On MouseUp you would terminate this "select by movement" mode. As for the drawing of the fancy "blue box" this would have to be a div of some sort with a transparency mask that is hooked to your MouseListener using the mouse down location to the current location on the mouse move.
I know this is really rough, but seems quite doable.
14 Sep 2009, 8:51 AM
It is indeed do-able. In fact I already have the clever DIV resizing and following your mouse around with a nice looking transparent background. I have used the SelectionModel's select method and have successfully managed to get the solution to partially work.
I say partially because: when capturing mouse movements, the vent object will return the exact ModelData item that the mouse is moving over. We can then use this to select that document. However, if I put the mouse pointer in the bottom right hand corner and drag it to the top left hand corner an issue happens:
All the ModelData items on the diagonal path of the mouse will have been selected, but the items where the mouse didn't hover over, but that are still under the DIV are not highlighted!
Still not quite sure how to fix that... Any ideas would be great :-)
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.