The ListView control which ships with ODE doesn't have a FullRowSelect
property like it's VB6 cousin. The FullRowSelect property allows you to specify if
the entire row of the selected item is highlighted and clicking anywhere on an item's row
causes it to be selected.
By using the SendMessage API function, we can send the
LVM_SETEXTENDEDLISTVIEWSTYLE message, with lParam value set to True, to the ListView
window which enables the FullRowSelect feature. To revert back to the normal select
mode, we call SendMessage again with LVM_SETEXTENDEDLISTVIEWSTYLE and flip the lParam
value to False.
Here are two functions to set and clear this style for a ListView
control.
Private Const LVM_FIRST As Long = &H1000
Private Const LVS_EX_FULLROWSELECT As Long = &H20
Private Const LVM_SETEXTENDEDLISTVIEWSTYLE As Long = LVM_FIRST + 54
Private Const LVM_GETEXTENDEDLISTVIEWSTYLE As Long = LVM_FIRST + 55
Private Declare Function apiSendMessageLong Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal Msg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Function fLVFullRowSelect(LV As Control) As Boolean
Dim lngStyle As Long
lngStyle = apiSendMessageLong(LV.hwnd, _
LVM_GETEXTENDEDLISTVIEWSTYLE, _
0&, 0&)
If lngStyle And LVS_EX_FULLROWSELECT Then
fLVFullRowSelect = True
Else
fLVFullRowSelect = (apiSendMessageLong(LV.hwnd, _
LVM_SETEXTENDEDLISTVIEWSTYLE, _
LVS_EX_FULLROWSELECT, True) = 0)
End If
End Function
Function fResetLVFullRowSelect(LV As Control) As Boolean
Dim lngStyle As Long
lngStyle = apiSendMessageLong(LV.hwnd, _
LVM_GETEXTENDEDLISTVIEWSTYLE, _
0&, 0&)
If lngStyle And LVS_EX_FULLROWSELECT Then
fResetLVFullRowSelect = Not (apiSendMessageLong(LV.hwnd, _
LVM_SETEXTENDEDLISTVIEWSTYLE, _
LVS_EX_FULLROWSELECT, 0) = 0)
Else
fResetLVFullRowSelect = True
End If
End Function
|