News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

ListBox a horizontal scroll bar

Started by nandagopal, May 20, 2009, 07:05 PM

Previous topic - Next topic

nandagopal

Use SendMessage to send the control the LB_SETHORIZONTALEXTENT message specifying the necessary width to display the list items.


Public Sub SetListboxScrollbar(ByVal lst As ListBox)
Dim i As Integer
Dim new_len As Long
Dim max_len As Long

    For i = 0 To lst.ListCount - 1
        new_len = 10 + lst.Parent.ScaleX( _
            lst.Parent.TextWidth(lst.List(i)), _
            lst.Parent.ScaleMode, vbPixels)
        If max_len < new_len Then max_len = new_len
    Next i

    SendMessage lst.hwnd, _
        LB_SETHORIZONTALEXTENT, _
        max_len, 0
End SubUse SendMessage to send the control the LB_SETHORIZONTALEXTENT message specifying the necessary width to display the list items.


Public Sub SetListboxScrollbar(ByVal lst As ListBox)
Dim i As Integer
Dim new_len As Long
Dim max_len As Long

    For i = 0 To lst.ListCount - 1
        new_len = 10 + lst.Parent.ScaleX( _
            lst.Parent.TextWidth(lst.List(i)), _
            lst.Parent.ScaleMode, vbPixels)
        If max_len < new_len Then max_len = new_len
    Next i

    SendMessage lst.hwnd, _
        LB_SETHORIZONTALEXTENT, _
        max_len, 0
End Sub