Tricky one for those that think they are GUI experts. How do you get a listbox to scroll horizontally.
Printable View
Tricky one for those that think they are GUI experts. How do you get a listbox to scroll horizontally.
Well, it needs to be done when the control is initialised, by using the WS_HSCROLL window style. Unfortunately, it can't be changed after it's been created. If a new list box was created, then it could be used that way. I'll try knocking up a more useful list box and get back to you.
[Edited by parksie on 08-03-2000 at 03:59 PM]
[Edited by HeSaidJoe on 08-03-2000 at 04:15 PM]Code:Option Explicit
Const LB_SETHORIZONTALEXTENT = &H194 'Used in the SendMessage function
Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Sub Form_Load()
dim x
X = SendMessage(List1.hwnd, LB_SETHORIZONTALEXTENT, 350, 0) 'Win API function to set the scrollbar
List1.AddItem ":DFJKD:JFLSDJFDSJFL:DSLF:JDSFJLSDJFLSDJFLSJLFDSFJLSDJFLDSJLKF"
End Sub
Doesn't work. The problem is with the window style, I think.
Thanks!
works fine on my pc...what are you running?
I just found a MS KB article on it, using your same method.
Option Explicit
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
Private Sub Command1_Click()
Dim s As String
Static x As Long
s = InputBox("Please enter any text", "List scroll", _
"this is a simple scrollbar sample for demonstration purposes")
List1.AddItem s
If x < TextWidth(s & " ") Then
x = TextWidth(s & " ")
If ScaleMode = vbTwips Then _
x = x / Screen.TwipsPerPixelX ' if twips change to pixels
SendMessageByNum List1.hwnd, LB_SETHORIZONTALEXTENT, x, 0
End If
End Sub
It should work:
Code:Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const LB_SETHORIZONTALEXTENT = &H194
Private Sub Command1_Click()
Call SendMessage(List1.hwnd, LB_SETHORIZONTALEXTENT, 350, 0)
End Sub
swine's KB method works...
HeSaidJoe: W98/PIII/VB5 Enterprise
Parksie:
weird stuff
...Megatron has exactly the same code and he is running VB5 and it works for him, so it should work on yours too...
I'm running 6...
OH..well, long as swine is happy and it works for him.
Later.
You're right. He needs it, and it works for him. That's all we're concerned about here. Although why it doesn't work on mine needs checking...I'll see what the problem is.