Mouse over tooltip

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
 
G

Guest

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.
 
K

Ken Tucker [MVP]

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
---------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top