Undocumented ListView Features : Part 5 - Explorer-style selection
See Also: Part 1 - Footer Items | Part 2 - Subsetted Groups | Part 3 - Groups With Virtual Mode | Part 4 - Column Backcolor
In Windows Explorer, when you're in Details View, you can start a selection marquee in the white space of columns. However in a ListView, even set to Explorer Style, dragging anywhere in the column starts a dragdrop operation (or does nothing if DD is disabled). It's possible to enable the multiselection marquee when dragging in the column whitespace like Explorer using the undocumented IListView interface's SetSelectionFlags call. There's no LVM_ message, so the only downside is a TLB is required.
Requirements
Windows 7 or newer - While Vista does have an IListView interface available under a different GUID, this call seems not to work.
oleexp.tlb v4.42 or higher (Recommended) or the deprecated lvundoc.tlb
oleexp Add-on mIID.bas (included in oleexp download) - If you want to use the old lvundoc.tlb, you can supply your own definition of IID_IListView.
First of all, obviously this is only applicable to Details View with Multiselect enabled, and this only applies to a ListView with Explorer Style enabled,
Code:
SetWindowTheme hWnd, StrPtr("explorer"), 0&
Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const LVM_FIRST = &H1000
Private Const LVM_QUERYINTERFACE = (LVM_FIRST + 189) 'UNDOCUMENTED
Private Sub LVSetExplSel(hwndLV As Long, bOn As Boolean)
Dim pILV As oleexp.IListView
SendMessage hwndLV, LVM_QUERYINTERFACE, VarPtr(IID_IListView), pILV
If (pILV Is Nothing) = False Then
pILV.SetSelectionFlags 1&, iif(bOn, 1&, 0&)
Else
Debug.Print "LVSetExplSel::Failed to get IListView"
End If
End Sub
If FullRowSelect is disabled, you can start a selection marquee from other columns regardless of the text. If FullRowSelect is enabled, the behavior of the first column applies to the others as well-- dragging from the text starts a dragdrop, dragging from the whitespace starts a multiselect marquee.