VB TIP: Using Header Track Selection in a Listview

Monday Nov 18th 2002 by Sam Huggill
Share:

Using header track selection in a listview.

Public Declare Function SendMessageByLong _
     Lib "user32" _
 Alias "SendMessageA" (ByVal hwnd As Long, _
              ByVal wMsg As Long, _
              ByVal wParam As Long, _
              ByVal lParam As Long) As Long

Public Declare Function GetWindowLong _
    Lib "user32" _
 Alias "GetWindowLongA" (ByVal hwnd As Long, _
                 ByVal nIndex As Long) As Long

Public Declare Function SetWindowLong _
   Lib "user32" _
 Alias "SetWindowLongA" (ByVal hwnd As Long, _
              ByVal nIndex As Long, _
              ByVal dwNewLong As Long) As Long

Public Const LVM_FIRST As Long = &H1000
Public Const LVM_GETHEADER = (LVM_FIRST + 31)
Public Const GWL_STYLE = -16&
Public Const HDS_HOTTRACK = &H4

Private Sub HeaderTrackSelect(lv As ListView)
    Dim lngHwnd As Long
    Dim lngStyle As Long

    lngHwnd = SendMessageByLong(lv.hwnd, _
                                LVM_GETHEADER, _
                                0, 0)
    If lngHwnd <> 0 Then
        lngStyle = GetWindowLong(lngHwnd, GWL_STYLE)
        lngStyle = lngStyle Or HDS_HOTTRACK
        SetWindowLong lngHwnd, GWL_STYLE, lngStyle
    End If
End Sub
Share:
Home
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved