Setting horizontal scroll bar for list boxes

For list boxes you may not be able to set horizontal scroll bar by using any property. When an item is longer than the width of the list box, you may like to put a horizontal scroll bar to view the entire string in that item. Include the following code in your program to do that.

 '*** Include this in the declaration
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Long) As Long

Const LB_SETHORIZONTALEXTENT = &H400 + 21
Const NUL = &O0
Dim mlExtralength As Long

'*** Include the following lines in the form load event
Dim lLreturnVal As Long

'Find out the length of the longest item
mlExtralength = 0

For i = 0 To LstTestItems.ListCount - 1
    If TextWidth(LstTestItems.List(i)) > mlExtralength Then
        mlExtralength = TextWidth(LstTestItems.List(i))
    End If
Next

'Convert twips into pixels which would be passed to SendMessage API
mlExtralength = mlExtralength / 15

'Add the horz. scroll bar for the list box.
lLreturnVal = SendMessage(LstTestItems.hwnd, LB_SETHORIZONTALEXTENT, mlExtralength, NUL)