Mouse over tooltip

  • Thread starter Thread starter Nikolay Petrov
  • Start date Start date
N

Nikolay Petrov

I have a ListBox, which is binded to a DataTable.
I would like to display a tooltip when the mouse cursor hovers over the
items in the ListBox.
I don't know how to find the index if ListBox item, on which mouse
cursor is over and how to display the tooltip.
Any suggestions?

TIA
 
In the ListBox's "MouseMove" event, you can track the mouse location and set
form level variables to it's X,Y location. Then in the MouseHover Event, you
can get the ListBox Index that the mouse is over from the IndexFromPoint
method and the X,Y form level variables. You can then assign ToolTip.Text
equal to whatever you want depending on the index that the mouse is hovering
over. Unfortunately, I haven't found a way to get the tooltip to redisplay
unless the mouse is moved out of the control then back over the control.
 
Hi,

When I use this code the tooltip is always displayed when the mouse
is over the listbox.

Private Sub ListBox2_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles ListBox2.MouseMove
Dim i As Integer = ListBox2.IndexFromPoint(e.X, e.Y)

If i >= 0 Then ToolTip1.SetToolTip(ListBox2,
ListBox2.Items.Item(i).ToString)

End Sub

Ken
---------------------------
 
Back
Top