TreeNode tooltip not showing

I am trying to show a tooltip when the mouse hovers over a treeview node. But the tooltip is not displayed.

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?

+7
c # winforms treeview mousehover
source share
2 answers

looks like a problem in

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

change it to

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

and it should work; I would also like to consider the following article: How to add a tooltip to a TreeNode in Visual C # for detalis on how to add tooltips to a treeview

hope this helps, believes

+4
source share

Much simpler:

  • Set ToolTipText to TreeNode when creating it.
  • Set the ShowNodeToolTips property of the TreeView control to True.

And you're done.

+24
source share

All Articles