Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox control - Getting the number of visible records

Status
Not open for further replies.

DevonTaig

Programmer
May 2, 2001
73
US
Is it possible to get the number of currently visible items in a listbox? The Listcount property returns the total number, but I only want the number of the ones that are currently displayed. The Topindex property returns the index of the top visible item, but there isn't a BottomIndex property. The Height property is in pixels...hmmmm...

Thanks for your help
 
Private Sub Command1_Click()
Dim x As Integer
For x = 1 To 20
List1.AddItem CStr(x)
Next


Dim strOldFont As String
Dim strOldFontSize As String
Dim sglTextHeight As Single
Dim intNumLines As Integer

'get current font for form
strOldFont = Me.FontName
'set form font to listbox font
Me.FontName = List1.Font

'get/set fontsize
strOldFontSize = Me.FontSize
Me.FontSize = List1.FontSize

'get text height
sglTextHeight = TextHeight("W")

'revert form to orig. settings
Me.FontName = strOldFont
Me.FontSize = strOldFontSize

'calculate # of full lines
intNumLines = List1.Height \ sglTextHeight

Label1.Caption = intNumLines

End Sub Tim

Remember the KISS principle:
Keep It Simple, Stupid!
 
Sorry, I b tired...section from above :

'get current font for form
strOldFont = Me.FontName
'set form font to listbox font
Me.FontName = List1.Font

'get/set fontsize
strOldFontSize = Me.FontSize
Me.FontSize = List1.FontSize

IS WRONG!!! SHOULD BE:

'get current font for form
strOldFont = Me.FontName
strOldFontSize = Me.FontSize
'set form font to listbox font
Me.FontName = List1.Font
Me.FontSize = List1.FontSize
Tim

Remember the KISS principle:
Keep It Simple, Stupid!
 
Interesting response Tim - I found another way that might be easier myself.


1. Add 40 or so items to the list box (enough so that scroll bars will always appear)
2. Set the ListIndex property to ListCount - 1 (that will position the pointer at the last item in the list)
3. Subtract ListIndex from TopIndex to get the number of rows being displayed.
4. Remove the 40 or so items that were added to the list box for testing.

This seems to go pretty quick.

Kieren
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top