Detect if vertical scrollbars visible in listbox ?

M

mscertified

I have a need to know if there is data that can be scrolled to in a listbox.
I'd rather not check the number of items listed since the height of the
listbox may change.
Is there a way to detect if the vertical scrollbars are visible or not?

Thanks.
 
S

Stephen Lebans

mscertified said:
I have a need to know if there is data that can be scrolled to in a
listbox.
I'd rather not check the number of items listed since the height of the
listbox may change.
Is there a way to detect if the vertical scrollbars are visible or not?

Thanks.

It would require a substantial amount of GDI API work that is really not
necessary if you can live with results that are 99% accurate. If you require
100% accuracy then look at the LisBox subclass in the ToolTips on my site.
You will have to use my logic in the Tooltips class if you need to know the
state of the ListBox SB in the form's Load event. If you simply need it at
runtime after the form is loaded then you can cut the requried code down to
a few lines.
SetFocus to the ListBox control
Grab it's hWnd(Private Declare Function GetFocus Lib "user32" () As Long )
Query this window to see if the SB is Visible or not.

The previous post of mine below gives you the logic/code to work out the
necessary details for a non API approach.. Use the code below to calcylate
how many rows fit intot he control at its current height. If the number of
total rows will fit then the ScrollBar is not requried or visible.


Newsgroups: microsoft.public.access.formscoding
From: "Stephen Lebans"
<[email protected]>
A far simpler solution, that is almost as accurate would be to use
code/logic like:

Assumes ListBox control named lbHeight
Assumes TestBox control named Text11
Assumes CommandButton named CmdSize


Enter a desired number of rows value in Text11 and then click on the
CommandButton.


Private Sub cmdSize_Click()
On Error GoTo Err_cmdSize_Click


Dim x As Integer


' convert Twips to TwipsPerPoint
x = 1440 / 72
' multiply font height x TwipsPerPoint
x = (x * Me.lbHeight.FontSize) * Val(Me.Text11.Value)
' Vertical space(margin)Access leaves between rows when more than 1 row
x = x + (Val(Me.Text11.Value) - 1) * 50


' Resize ListBox control to display Number Of Rows as expressed In Text1
' Access leaves around 100 Twips as a margin at the top of the ListBox
control
Me.lbHeight.Height = x + 100


Exit_cmdSize_Click:
Exit Sub


Err_cmdSize_Click:
MsgBox Err.Description
Resume Exit_cmdSize_Click


End Sub



--

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top