Select Entire Row In ListView
Preparations
Add 1 ListView Control to your
form.
Module Code
Const LVM_FIRST =
&H1000
Const LVM_SETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 54
Const
LVM_GETEXTENDEDLISTVIEWSTYLE = LVM_FIRST + 55
Const LVS_EX_FULLROWSELECT =
&H20
Declare Function SendMessageLong Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal Msg As Long, _
ByVal wParam
As Long, ByVal lParam As Long) As Long
Public Sub
LVFullRowSelect(lstvw As ListView)
Dim rs As
Long
Dim r As Long
rs =
SendMessageLong(lstvw.hwnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0&,
0&)
rs = rs Or LVS_EX_FULLROWSELECT
r =
SendMessageLong(lstvw.hwnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0&, rs)
End
Sub
Form Code
Private Sub Form_Load()
'the code
below add some items to the ListView
ListView1.ColumnHeaders.Add , , "Col1"
ListView1.ColumnHeaders.Add , ,
"Col2"
Dim itmx As ListItem
Set itmx =
ListView1.ListItems.Add(, , "Hello")
itmx.SubItems(1) =
"World"
ListView1.ColumnHeaders.Add , , "Col1"
ListView1.ColumnHeaders.Add , , "Col2"
Set itmx =
ListView1.ListItems.Add(, , "Hello")
itmx.SubItems(1) =
"World"
ListView1.View = lvwReport
'Trigger the
select entire row function
LVFullRowSelect ListView1
End Sub