By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,657 Members | 1,094 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,657 IT Pros & Developers. It's quick & easy.

Horizontal Scrollbar

P: n/a
Hi all you Experts,
I need to scroll a listbox horizontally.
For the life of me I cannot get it to move. I can successfully scroll
it vertically.
I have the handle for the listbox and the scroll bar.
I have even tried sending it vbKeyRight to no avail, but it doesn't
register the key strokes.

I am using
lDirection = WM_HSCROLL
lThumb = MakeDWord(SB_THUMBPOSITION, CInt(lIndex))
SendMessage hwReportList, lDirection, lThumb, hwScrollBar

Is there anything else I can try? Am I missing something?
Thanks

Private Function MakeDWord(loword As Integer, hiword As Integer) As
Long
'************************************************* **********
' Here's the MakeDWord function from the MS KB
'************************************************* **********
On Error Resume Next
MakeDWord = (hiword * &H10000) Or (loword And &HFFFF&)
End Function

Dec 20 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Can you just make the listbox longer? I know that's not the best
option, but it's the laziest :) It's also guaranteed to work if your
data is usually about the same length. Not very technical, but easy to
implement.

Dec 20 '05 #2

P: n/a
Thanks Steve,
I wish I could, but the form width is not something I can't change so
I'm stuck with the list width I have too.

Dec 20 '05 #3

P: n/a
There's sample code on my site here:
http://www.lebans.com/setgetsb.htm
SetGetSB.zip is a database containing functions to allow a user to Set or
Get the current position of a ScrollBar Thumb for a Form.

NEW - Apr. 02/2000 The current ScrollBar position is equal to the current
Record Number being displayed at the Top of the Form.

Works in Form or Datasheet view.

Ver 1.7

Fix bug in SelTop method. Now works with first page of rows properly and
sets the Top row correctly when moving forward in the recordset one row at a
time.

Ver 1.6

Use SelTop to save Restore current row's position after a Requery.

Ver 1.5

Added support for Horizontal ScrollBars.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Pachydermitis" <pr*******@gmail.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
Hi all you Experts,
I need to scroll a listbox horizontally.
For the life of me I cannot get it to move. I can successfully scroll
it vertically.
I have the handle for the listbox and the scroll bar.
I have even tried sending it vbKeyRight to no avail, but it doesn't
register the key strokes.

I am using
lDirection = WM_HSCROLL
lThumb = MakeDWord(SB_THUMBPOSITION, CInt(lIndex))
SendMessage hwReportList, lDirection, lThumb, hwScrollBar

Is there anything else I can try? Am I missing something?
Thanks

Private Function MakeDWord(loword As Integer, hiword As Integer) As
Long
'************************************************* **********
' Here's the MakeDWord function from the MS KB
'************************************************* **********
On Error Resume Next
MakeDWord = (hiword * &H10000) Or (loword And &HFFFF&)
End Function

Dec 20 '05 #4

P: n/a
Thanks Stephen,
I actually downloaded that and tried your methodology (slightly
modified of course) on my list box a couple days ago - to no avail.
Your solution is pretty slick. Thanks for making that available to
everyone.
Were you able to get a listbox to scroll horizontally?

Dec 20 '05 #5

P: n/a
Oh...you're working with a ListBox not a Form's ScrollBar. Sorry about
that.One is a control and the other is not if I remember correctly.

Have you tried changing the code on my site to work with a Horizontal
Scrollbar?

Method #2

Here's the code to force a ListBox to Scroll to a specific row. I put it
behind a Command Button Named Customer, you can obviously do
whatever you want. Really should be a Class Wrapper for a ListBox to expose
a TopIndex property like VB ListBoxes.

' ***CODE START
'Place this code in the General Declarations of your Form
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 Declare Function GetFocus Lib "user32" () As Long

' Windows Message Constant
Private Const WM_VSCROLL = &H115
' Scroll Bar Commands
Private Const SB_THUMBPOSITION = 4
' Code end for General Declarations
' Code for Control's Click Event
Private Sub Customer_Click()

Dim hWndSB As Long
Dim lngRet As Long
Dim lngIndex As Long
Dim LngThumb As Long

' You will get lngIndex value from the user or whatever.
' For now I'm just setting it to arbitrary Number
lngIndex = 45

' SetFocus to our listBox so that we can
' get its hWnd
Me.List2.SetFocus
hWndSB = GetFocus

' Set the window's ScrollBar position
LngThumb = MakeDWord(SB_THUMBPOSITION, CInt(LngIndex))
lngRet = SendMessage(hWndSB, WM_VSCROLL, LngThumb, 0&)

End Sub

' Here's the MakeDWord function from the MS KB
Function MakeDWord(loword As Integer, hiword As Integer) As Long MakeDWord =
(hiword * &H10000) Or (loword And &HFFFF&) End Function '***END CODE
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.

"Pachydermitis" <pr*******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Thanks Stephen,
I actually downloaded that and tried your methodology (slightly
modified of course) on my list box a couple days ago - to no avail.
Your solution is pretty slick. Thanks for making that available to
everyone.
Were you able to get a listbox to scroll horizontally?

Dec 20 '05 #6

P: n/a
Once again thanks for the suggestion(s).
I have been scrolling the box vertically for quite some time using very
similar code. My problem arose when I needed to scroll it
horizontally. I have tried every permutation of the above code that I
can think of in order to scroll Horizontally, but it won't move. For
interests sake I do have the this code in a class.
Thanks again.

Dec 21 '05 #7

P: n/a
If you want to ZIP and email me your MDB containing your working Vertical
and test Horizontal code I will have a look at it for you.
My*********@MyLastName.com

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Pachydermitis" <pr*******@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
Once again thanks for the suggestion(s).
I have been scrolling the box vertically for quite some time using very
similar code. My problem arose when I needed to scroll it
horizontally. I have tried every permutation of the above code that I
can think of in order to scroll Horizontally, but it won't move. For
interests sake I do have the this code in a class.
Thanks again.

Dec 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.