listbox height

  • Thread starter Thread starter Miranda
  • Start date Start date
M

Miranda

hi,
i have a listbox that displays some data retrieved via a query. I want to
want the listbox big enough to fit the number of rows retrieved, no bigger,
no smaller. i tried something like this:

me.mylistbox.height = 0.5 * (me.mylistbox.listcount)

because 0.5cm was roughly the height of a single row....didn't work though

???

Thanks!!
 
When setting the height using code, the unit of measurement
is a twip. If you try something along the line of

me.mylistbox.height = 284 * (me.mylistbox.listcount)

you should get the effect that you are after.

Hope That Helps
Gerald Stanley MCSD
 
I don't think it's possible with a ListBox, but it is with a ComboBox
The following code will automatically open the Combo (to make it look
little like a ListBox) and fill it with all the records. Just chang
"YourCombo" to the Combo's name.

Code
-------------------

Private Sub Form_Load()

Me.YourCombo.SetFocus
Me.YourCombo.Dropdown

Dim ListControl As Control

Set ListControl = Me.YourCombo
With ListControl
If .ListCount > 0 Then
.ListRows = .ListCount
Else
.ListRows = 0
End If
End With

End Sub
 
There is sample code showing how to autosize a ListBox control here:
http://www.lebans.com/textwidth-height.htm
TextHeightWidth.zip is a replacement for the Report object's TextWidth
and TextHeight methods. It is multiline aware and can work in both
Report and Form views. Includes a sample report to show you how to
autosize individual controls with different formatting on the same line
to simulate RTF style text.

History

Version 4.5: Increased accuracy of auto sizing for a ListBox.

Version 4.3: Added sample Form to demonstrate auto sizing for a ListBox.

Version 4.2: Added report to demonstrate auto sizing to mix text
formatting on one row.

--

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