VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Changing tooltip text for multiple listbox entries

by William A. Henderson I (1 Submission)
Category: VB function enhancement
Compatability: Visual Basic 3.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

The purpose of this code is to display a tooltip giving a description of each entry in a listbox.

Inputs
Standard inputs relative to the MoveMouse event.
Assumes
Familiarity with the ItemData property of the listbox control.

Rate Changing tooltip text for multiple listbox entries

'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

Download this snippet    Add to My Saved Code

Changing tooltip text for multiple listbox entries Comments

No comments have been posted about Changing tooltip text for multiple listbox entries. Why not be the first to post a comment about Changing tooltip text for multiple listbox entries.

Post your comment

Subject:
Message:
0/1000 characters