Results 1 to 1 of 1

Thread: [VB6, Win7+] Undocumented ListView Feature: Multiselect in columns like Explorer

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jul 2010
    Location
    NYC
    Posts
    5,651

    [VB6, Win7+] Undocumented ListView Feature: Multiselect in columns like Explorer

    Name:  exsel.jpg
Views: 1251
Size:  35.6 KB

    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&
    Once your ListView is set up, here's what you need:

    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
    It can be toggled on and off, use bOn = True to turn it on.

    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.
    Last edited by fafalone; Jan 13th, 2022 at 11:19 PM. Reason: Applies to other columns too

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width