Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 32,393 times

Related Categories

Add Horizontal ScrollBars to a ListBox

Kimmy

The standard VB listboxes don`t support horizontal Scrollbars, only vertical ones. Here's an API work-around to get you one!

' In General Declarations
Private Declare Function SendMessageByNum Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal _
wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Const LB_SETHORIZONTALEXTENT = &H194

To display the horizontal scroll bar, you then just call

SendMessageByNum List1.hwnd, LB_SETHORIZONTALEXTENT, 250, 0

List1.hwnd is replaced with the name of your list box, and 250 is replaced with the width you want the scroll bar to be. If you give a width of 0, then the scrollbar will be disappear. This sub routine will automatically workout the greatest width needed.

Sub lstAddHScroll(lst as ListBox)
    ' depends on the scalewidth
    ' if scalemode is Twips then Divide M by 15 to get Pixels

    For a=0 to lst.listcount-1
        if me.textwidth(lst.list(a))>m then m=me.textwidth(lst.list(a))
    Next

    SendMessageByNum lst.hwnd, LB_SETHORIZONTALEXTENT, m/15, 0
End Sub

Till the Roof comes off Till the Lights go out Till my Legs give out Can't shut my mouth I will not fall, my Wisdoms all.

Comments

  • Better way of adding a horizontal scrollbar

    Posted by stanis on 11 Feb 2003

    Hi!

    I have come up with a better way of adding a horizontal scrollbar to the listbox. It is a class module that attaches itself to one listbox. The nice thing is that it also handles RemoveItem, pr...