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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listbox row height

Status
Not open for further replies.

EagleTempest

Technical User
Jun 15, 2004
125
CA
I working with the mousemove event on a listbox and want to determine the row number the mouse is over.

Is the row height in a list box the same as the font height?

Is there a way I can get the row height from a listbox in VBA?
 



Hi,

Well what do we know relative to the verticle parameters.

The HEIGHT of the listbox.

The NUMBER OF ROWS in the listbox.

I'd make two passes with two different number of rows and solve a
[tt]
y = mx + b
[/tt]
using the values form the two examples, where b is the constant in the height related to the title bar and border.

Skip,

[glasses] [red][/red]
[tongue]
 



Well, my shoot-from-the-lip was way off.

How about something like this...
Code:
Private Sub ListBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
Application.StatusBar = Int((Y / ListBox1.Height) * 5) + 1
End Sub
where 5 is the number of rows

Skip,

[glasses] [red][/red]
[tongue]
 
That works except if there are more items in the list than displayed list rows. So if I have 100 items in a listbox with 25 rows, it only works properly for the first 25 items in the list.

I need to figure out how to tie the mouse row to actual row in the listbox. Item 50 in the list could be at row "two" according to the mousemove calculation.

I guess I could hide in a column it's actual row number and retrieve that number when the mouse is over it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top