tags:

views:

293

answers:

2

I have a ListView where several items have more text than fits in the column width. ShowItemToolTips means i can hover over a column and see the full text which is great.

However, for really long texts, it disappears before there is time to read everything, so i would like to make it stay longer (or possibly until the dismissed manually, eg by moving away the mouse or clicking. How do I do this?

A: 

Check out the ToolTip class. The AutoPopupDelay method allows you to set the length of time the tooltip remains visible.

Malcolm Post
sure, but how do i find the instance to change? (the one automatically generated for subitems with too much text to fit) subitems don't seem to have a tooltip property...
second
+4  A: 

You know, of course, that underneath the .NET ListView class is a Windows listview control. This listview control uses a Windows tooltip control to show the truncated strings.

You can get hold of this underlying tooltip control through the LVM_GETTOOLTIPS message.

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, int msg, 
                                        int wParam, int lParam);

public IntPtr GetTooltipControl(ListView lv) {
    const int LVM_GETTOOLTIPS = 0x1000 + 78;
    return SendMessage(lv.handle, LVM_GETTOOLTIPS, 0, 0);
}

Once you have the handle to the tooltip control, you can send messages to it.

public void SetTooltipDelay(ListView lv, int showTime) {
   const int TTM_SETDELAYTIME = 0x400 + 3;
   const int TTDT_AUTOPOP = 2;

   IntPtr tooltip = this.GetTooltipControl(lv);
   if (tooltip != IntPtr.Zero) {
      SendMessage(tooltip, TTM_SETDELAYTIME, TTDT_AUTOPOP, showTime);
   }
}

showTime is the number of milliseconds you want the control to stay visible.

Grammarian
@Grammarian: Thanks for this - I stumbled upon this answer while searching for something else, and now my product is slightly better than it was five minutes ago. Wonderful!
RichieHindle