We help IT Professionals succeed at work.

Windows ListView subitems tooltip not working

I have list view with fullrowselect property true.
I set ListView.ShowItemToolTips = true;
I want to give tooltip for 1 subitem.
There is no tooltiptext property for subitems.
How can I do this?
Comment
Watch Question

SILVER EXPERT
Commented:
Hi rishaan,

You'll need to use the MouseMove() event of the listview to show tooltips from the subitems. See the below code for an example.

Regards,

Wayne
public class Form1
{
    
    private void Form1_Load(object sender, System.EventArgs e)
    {
        for (int i = 1; i <= 5; i++) {
            ListViewItem lvi = ListView1.Items.Add("Item" + i);
            lvi.ToolTipText = lvi.Text;
            for (int s = 1; s <= 5; s++) {
                ListViewItem.ListViewSubItem lvsi = lvi.SubItems.Add("Item" + i + " - " + "SubItem" + s);
                lvsi.Tag = lvsi.Text;
            }
        }
    }
    
    private void ListView1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        ListViewHitTestInfo ht = ListView1.HitTest(e.Location);
        if ((ht.SubItem != null)) {
            ToolTip1.Show(ht.SubItem.Tag, sender, ht.SubItem.Bounds.Location, 2000);
        }
    }
    
}

Open in new window

Author

Commented:
How to define Tooltip

       ToolTip1.Show(ht.SubItem.Tag, sender, ht.SubItem.Bounds.Location, 2000);
     
SILVER EXPERT

Commented:
Add a tooltip control to your form.

Author

Commented:
Error      5      The best overloaded method match for 'System.Windows.Forms.ToolTip.Show(string, System.Windows.Forms.IWin32Window, System.Drawing.Point, int)' has some invalid arguments

Error      6      Argument '2': cannot convert from 'object' to 'System.Windows.Forms.IWin32Window'
SILVER EXPERT

Commented:
Either turn Option Strict Off, or convert "sender" to a ListView (which it is). The best way to find out the appropriate object types for methods is to use the F1 key.
ToolTip1.Show(ht.SubItem.Tag, (ListView)sender, ht.SubItem.Bounds.Location, 2000);

Open in new window

Author

Commented:
It works ...Thanks a lot.....Is it possible to display this tooltip on headercell.
SILVER EXPERT

Commented:
You mean when the mouse is over a column header? No, unfortunately there's not.

Author

Commented:
Yes
But the tooltip is diplaying over the subitem text itself.It should diplay slightly down to the subitem text.