This topic shows you how to select a full row in a Listview control in report view.

Microsoft Visual Basic 5.0

This document has been viewed times since February 22, 1998.
Last modified on February 22, 1998.

'At top level of a module, always include to be sure that all variables have the right type
Option Explicit

'Then declare these constants. LVM_FIRST is base code
Private Const LVM_FIRST As Long = &H1000

'LVM_SETEXTENDEDLISTVIEWSTYLE is for retreiving style of Listview
Private Const LVM_SETEXTENDEDLISTVIEWSTYLE As Long = LVM_FIRST + 54

'LVM_GETEXTENDEDLISTVIEWSTYLE is for setting style of Listview
Private Const LVM_GETEXTENDEDLISTVIEWSTYLE As Long = LVM_FIRST + 55

'LVS_EX_FULLROWSELECT is to tell Windows that a full row is to be selected
Private Const LVS_EX_FULLROWSELECT As Long = &H20

'Then decleare SendMessage for sending Windows message in order to worj with the Listview Control
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

'Then all we have to do is to write a public sub like this...
Public Sub lvwSelectFullRow(ByVal lvw As ComctlLib.ListView)

'Declare a old style variable lOldStyle, a new style variable lNewStyle
Dim lOldStyle As Long, lNewStyle As Long

'and an error value variable lResult
Dim lResult As Long

'Turn on error trapping
On Error Resume Next

'Get the current style for the Listvoew control
lOldStyle = SendMessage(lvw.hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&, ByVal 0&)

'Now mix the new style LVS_EX_FULLROWSELECT for selecting a full row
lNewStyle = lOldStyle Or LVS_EX_FULLROWSELECT

'OK, so far so good. Now send back the new style to the Listview control
lResult = SendMessage(lvw.hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, ByVal lNewStyle)

End Sub

Please email me suggestions, improvements or anything else you want to be included on my pages.