Listbox Height Question
The ListBox1.Height = Count * 12 + 2 is apparently counting the number of
items and multiplying by 12 points which would be the font row height, plus 2
points so that it will all display. You do not need the Count to adjust the
height. You can set the height to any number or points that you want with:
ListBox1.Height = 150
sets the height to 150 points. Same syntax for width.
With the code you posted, the list box will adjust itself based on the
number of items, so that it neither hides items nor leaves a big empty space.
"Norm Lundquist" wrote:
This is a follow-up to a previous question about How to set a listbox "Top".
(It should have been HEIGHT!)
The following code is in the Initialize event of a user form:
ListBox1.Height = Count * 12 + 2
' For some reason, we must access the height.
MsgBox "ListBox1.Height from init = " & ListBox1.Height, vbInformation,
"List Box Height"
' t = ListBox1.Height
"Count" is the number of items that has been loaded into ListBox1. For some
reason, setting the height does not work unless it is accessed - like in the
"MsgBox" line. I tried setting t = ListBox1.Height, but that does not work.
The height of the listbox is either done correctly when the MsgBox statement
is used; OR it is set to 49.2.
Any ideas on what's happening???
THANK YOU!
|