Solved

Listbox Horizontal Scroll

Posted on 1998-11-04
3
702 Views
Last Modified: 2013-12-26
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
0
Comment
Question by:Edithf
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
Mirkwood earned 80 total points
ID: 1488121
Const LB_SETHORIZONTALEXTENT = &H194
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
     (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
     lParam As Any) As Long

Dim x As Long
x = SendMessage(list1.hWnd, LB_SETHORIZONTALEXTENT, list1.Width * 2, _
     ByVal 0&)

Note: the `list1.Width*2' parameter specifies the scrollable width of the
listbox in pixels. You may need to adjust the form's ScaleMode or
otherwise experiment to find the best value.
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1488122
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

0
 
LVL 1

Author Comment

by:Edithf
ID: 1488123
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 ?
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now