Link to home
Start Free TrialLog in
Avatar of Edithf
Edithf

asked on

Listbox Horizontal Scroll

How do you add a horizontal scroll bar to a list box ?
I have only one column but the text lenght for each row is actually longer the listbox width I defined. I could not found a horizontal scroll bar function.

Vertical Scroll bar appears when the row gets bigger than the lenght of the listbox, but I cannot do that for horizontal ??

Thanks

Edith
ASKER CERTIFIED SOLUTION
Avatar of Mirkwood
Mirkwood

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mirkwood
Mirkwood

Here is also a function for automatic adjustment. Call this function whenever the listbox is changed.

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 WM_USER = &H400
Const LB_SETHORIZONTALEXTENT = WM_USER + 21

Sub CheckListBox
    Dim i%, res&
    Dim Scrollwidth&
   
    For i% = 0 To Form1.List1.ListCount
       If Form1.TextWidth(Form1.List1.List(i%)) > Scrollwidth& Then _
        Scrollwidth& = Form1.TextWidth(Form1.List1.List(i%))
    Next i%

    res& = SendMessage(Form1.List1.hWnd, LB_SETHORIZONTALEXTENT, _
        Scrollwidth&, 0&)
End Sub

Avatar of Edithf

ASKER

Thanks it works well now ....... I always have problem looking up for the function in the Library. Does the library function include in the C++ help ?