You know that each item in a ListView
has a ToolTipText
property and that\'s all! There is no property like AutoPopDelay
to set its displa
MouseHover fires once per control - so is never updated as you move to different items.
Use ListView.ItemMouseHover to accomplish what you need.
void listView1_ItemMouseHover(object sender, ListViewItemMouseHoverEventArgs e)
{
this.toolTip1.SetToolTip(e.Item.ListView, e.Item.ToolTipText);
}
To Hans Passant.
I used this code in MouseHover event:
Point pntOnList = lsvSource.PointToClient
(new Point(Cursor.Position.X, Cursor.Position.Y));
ListViewItem lsviUnderMouse =
lsvSource.GetItemAt(pntOnList.X, pntOnList.Y);
if (lsviUnderMouse != null)
{
ttipDetails.SetToolTip(lsvSource, lsviUnderMouse.ToolTipText);
ttipDetails.Active = true;
}
else
{
ttipDetails.Active = false;
}
But it behaves strangely. Actually the ToolTip's text is always outdated.
You can get the ToolTip
of the ListView
using LVM_GETTOOLTIPS, then send a TTM_SETDELAYTIME message to the tooltip and set its delay by passing TTDT_AUTOPOP
as wparam and the delay in millisecond as lparam.
Also make sure ShowItemsToolTip
property of the ListView
has been set to true and the items have tooltip.
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
const int LVM_GETTOOLTIPS = 0x104E;
const int TTM_SETDELAYTIME = 0x403;
const int TTDT_AUTOPOP = 2;
private void button1_Click(object sender, EventArgs e)
{
var tooltip = SendMessage(listView1.Handle, LVM_GETTOOLTIPS, 0, 0);
SendMessage(tooltip, TTM_SETDELAYTIME, TTDT_AUTOPOP, 10000 /*milliseconds*/);
}
To set the initial delay or the reshow delay, set the following values for wparam:
const int TTDT_AUTOMATIC = 0;
const int TTDT_AUTOPOP = 2;
const int TTDT_INITIAL = 3;