ListView selection

This is the forum for miscellaneous technical/programming questions.

Moderator: 2ffat

ListView selection

Postby HsiaLin » Wed Sep 21, 2016 11:27 am

Is it possible to force listview into mouse selection mode?
Maybe with a SendMessage(ListView1->Handle, WM_BEGINSELECT, 1) :-)
call or something.
HsiaLin
BCBJ Master
BCBJ Master
 
Posts: 277
Joined: Sun Jul 08, 2007 6:29 pm

Re: ListView selection

Postby theLizard » Sat Sep 24, 2016 4:12 pm

HsiaLin wrote:Is it possible to force listview into mouse selection mode?


I know that with ListView you can hold left mouse button down and drag over List View items and/or Ctrl Click Items when non contiguous selection is required, I use this approach with my Desk Top Organizer (uses ListView) http://bcbhelper.com/downloads/DeskTopOrganizer.zip

Is this what you mean?
theLizard
BCBJ Master
BCBJ Master
 
Posts: 439
Joined: Wed Mar 18, 2009 2:14 pm

Re: ListView selection

Postby HsiaLin » Sat Sep 24, 2016 8:26 pm

theLizard wrote:I know that with ListView you can hold left mouse button down and drag over List View items and/or Ctrl Click Items when non contiguous selection is required, I use this approach with my Desk Top Organizer (uses ListView) http://bcbhelper.com/downloads/DeskTopOrganizer.zip

Is this what you mean?


I mean you know how you can click with a mouse in the background area and it starts drawing a square
and allows you to select items. I was wondering if its possible to have it do that in the middle of a list
of say 1000 items, you click on item index 500 and drag it...say to the right 25 pixels it can be made to
go into mouse selection mode. In windows 10 the listview mouse selection only works by clicking on the
very bottom of the list in report mode. In windows explorer you can mouse select from anywhere in the list. Would be interesting to try to derive a listview component and add that capability. Some people call it lasso selecting.
HsiaLin
BCBJ Master
BCBJ Master
 
Posts: 277
Joined: Sun Jul 08, 2007 6:29 pm

Re: ListView selection

Postby rlebeau » Mon Sep 26, 2016 6:42 pm

HsiaLin wrote:In windows explorer you can mouse select from anywhere in the list.


That is utilizing an undocumented feature of ListView controls:

Marquee (lasso) selection in full row selection mode Pin

I just discovered another undocumented feature, which is used by Windows Vista's Explorer if I remember correctly: If full row selection is enabled, it's difficult to select multiple items by dragging a lasso around them. If you call the SetSelection method of the IListView interface with both parameters set to 0x1, the list view won't select items if you click onto the empty space in the item's row, or to be more precise: selection is done on mouse-up then, not on mouse-down. This provides easier marquee selection in full row selection mode.

However, this feature is buggy. It assumes that all columns contain left-aligned text. In columns that contain centered or right-aligned text, behavior is a bit strange, because clicking onto a row's white space can select the item row as well as start marquee selection - depending on whether the click position is to the right of where the text would end if it was left-aligned.


Also see Allow selection in Explorer-style list view to start in the first column on StackOverflow.

Actually there is a way to mimic Explorer selection behavior. It requires a lot of additional declarative work, but it is possible.

You need to get undocumented IListView interface via undocumented LVM_QUERYINTERFACE message (note that interface declaration and GUIDs are different for Windows Vista and Windows 7+). Details about constants and declarations can be found here:

IListView at Geoff Chappell - Software Analyst or

Undocumented List View Features at Code Project.

After acquiring the interface all you need is simply a call to SetSelectionFlags(1, 1) method. Voila you are done.
Last edited by rlebeau on Thu Sep 29, 2016 5:25 pm, edited 1 time in total.
Remy Lebeau (TeamB)
Lebeau Software
User avatar
rlebeau
BCBJ Author
BCBJ Author
 
Posts: 1376
Joined: Wed Jun 01, 2005 3:21 am
Location: California, USA

Re: ListView selection

Postby HsiaLin » Mon Sep 26, 2016 8:56 pm

Thats interesting info, thanks remy.
HsiaLin
BCBJ Master
BCBJ Master
 
Posts: 277
Joined: Sun Jul 08, 2007 6:29 pm


Return to Technical

Who is online

Users browsing this forum: Bing [Bot] and 4 guests