VB icon

Changing tooltip text for multiple listbox entries

Email
Submitted on: 1/5/2015 7:37:00 AM
By: William A. Henderson I (from psc cd)  
Level: Advanced
User Rating: By 3 Users
Compatibility: VB 5.0, VB 6.0
Views: 541
 
     The purpose of this code is to display a tooltip giving a description of each entry in a listbox.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Changing tooltip text for multiple listbox entries
' Description:The purpose of this code is to display a tooltip giving a description of each entry in a listbox.
' By: William A. Henderson I (from psc cd)
'
' Inputs:Standard inputs relative to the MoveMouse event.
'
' Assumes:Familiarity with the ItemData property of the listbox control.
'**************************************

'FACED WITH THE PROBLEM OF SHOWING OFFICE CODES
'FOR OFFICES WITH DUPLICATE NAMES IN A LISTBOX, 
'AND NOT WANTING TO INCUDE THE NUMBER IN THE 
'TEXT ENTRY IN THE LISTBOX, I DEVELOPED A QUICK
'WAY OF SHOWING THE NUMBER WHICH WAS STORED IN
'THE LISTBOX ITEMDATA PROPERTY.
'
'NOTE:
'WordHeight = 195 (depending on the font used).
'
'THIS CODE IS AN IMPROVEMENT UPON CODE PREVIOUSLY
'SUBMITTED BY ANOTHER VB PROGRAMMER INWHICH THE
'PROGRAMMER LOOPED THROUGH EVERY ITEM IN THE 
'LISTBOX TO DETERMINE WHICH TEXT TO DISPLAY IN THE
'TOOLTIP. THE PROBLEM ENCOUNTERED BY THAT CODE WAS
'THAT IT DID NOT WORK FOR LARGE LISTBOXES WITH 
'ENTRIES GREATER THAN 167. ON THE 168th ENTRY, AN
'OVERFLOW ERROR WAS ENCOUNTERED. MY CODE IS FASTER
'AND TAKES YOU DIRECTLY TO THE ENTRY WITHOUT 
'LOOPING THROUGH THE LIST.
'
Private Sub ListBox1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim index As Integer
index = ListBox1.TopIndex + ((Y) / WordHeight)
ListBox1.ToolTipText = Str(ListBox1.ItemData(index))
End Sub


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.