Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TreeNode mouse hover tooltip not showing up

I am trying to show a tooltip when mouse hovers on a treeview node. But the tooltip is not showing up.

This is my code:

private void treeView1_MouseHover(object sender, EventArgs e)
{
    toolTip1.RemoveAll();

    TreeNode selNode = (TreeNode)treeView1.GetNodeAt(Cursor.Position);

    if (selNode != null)
    {
        if (selNode.Tag != null)
        {
            Product selProduct = selNode.Tag as Product;

            if (selProduct != null)
            {
                toolTip1.SetToolTip(treeView1, selProduct.ProductName + "\n" + selProduct.ProductCategory.ToString());
            }
        }
    }
}

What should I check for?

like image 592
user366312 Avatar asked Nov 18 '09 16:11

user366312


2 Answers

A much simpler way is to:

  1. Set the ToolTipText on the TreeNode when you create it.
  2. Set the TreeView control's ShowNodeToolTips property to True.

And you're done.

like image 136
Jeff Roe Avatar answered Sep 19 '22 20:09

Jeff Roe


looks like the problem is in the

TreeNode selNode = (TreeNode)treeView1.GetNodeAt(Cursor.Position);

line, change it to

TreeNode selNode = (TreeNode)treeView1.GetNodeAt(treeView1.PointToClient(Cursor.Position));

and it should work; I would also recomd to look at the following article: How to add a ToolTip to a TreeNode in Visual C# for detalis on how to add tooltips to the treeview

hope this helps, regards

like image 39
serge_gubenko Avatar answered Sep 22 '22 20:09

serge_gubenko