This little sniplet of code allows you to hover over a listbox and select the item the mouse is over and also show the items value. It may also come in handy if you want to show a tooltip text of the item your over. Hope it maybe usfull.
You need to place a listbox and a label control on your form, Then paste the code below in to the general selection of your form.
Code:Private Declare Function GetScrollPos Lib "user32.dll" (ByVal hwnd As Long, ByVal nBar As Long) As Long Private Sub Form_Load() Dim X As Integer 'Add some items to a listbox For X = 0 To 50 Call List1.AddItem("This item index is: " & CStr(X)) Next X List1.FontSize = 18 Set Me.Font = List1.Font End Sub Private Sub List1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) Dim yPos As Long 'Get Item Position in the list yPos = (Y \ Me.TextHeight("A")) + GetScrollPos(List1.hwnd, &H1) 'Move to the list index List1.ListIndex = yPos 'Show listbox index value in label Label1.Caption = List1.List(yPos) End Sub




Reply With Quote