Microsoft & .NETVisual BasicVB TIP: Using Header Track Selection in a Listview

VB TIP: Using Header Track Selection in a Listview

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

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

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories