ListView_SetFullRow


Description:
Single function to toggle full row select for a ListView control (for use in report mode). I really prefer full row select in a ListView, it would be nice if VB supported this, so I didn't have to call this function for every ListView.
 
Code:
Option Explicit

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 LVS_EX_FULLROWSELECT = &H20
Private Const LVM_FIRST = &H1000
Private Const LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54
Private Const LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55

Public Sub ListView_SetFullRow( _
   lvToSet As ListView, _
   bFullRow As Boolean)

    Debug.Assert lvToSet.View = lvwReport

    Dim exStyle As Long
    
    exStyle = SendMessage(lvToSet.hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, _
                          ByVal 0)
    
    If bFullRow Then
        exStyle = exStyle Or LVS_EX_FULLROWSELECT
    Else
        exStyle = exStyle And Not LVS_EX_FULLROWSELECT
    End If
    
    SendMessage lvToSet.hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, _
                LVS_EX_FULLROWSELECT, ByVal exStyle

End Sub

 
Sample Usage:
 
ListView_SetFullRow ListView1, True