Adding tooltip to TreeView node

  • Thread starter Thread starter Dmitry Karneyev
  • Start date Start date
Hi!
How to add tooltip to a TreeView node?

Here is one way that you could do:
Fill out the tag property for the treenodes and on mousemove event, update
the tooltip control with the tag property of the current node.



private void Form1_Load(object sender, System.EventArgs e)
{
TreeNode rootNode = this.treeView1.Nodes [0];
rootNode.Tag="This is the node 0";
rootNode.Nodes[0].Tag="this is node 1";
rootNode.Nodes[0].Nodes[0].Tag="this is node 2";

}

private void treeView1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{

TreeNode currentNode = this.treeView1.GetNodeAt(e.X,e.Y);
if (null != currentNode)
{
if (currentNode.Tag.ToString() !=
this.toolTip1.GetToolTip(this.treeView1).ToString())
{
this.toolTip1.SetToolTip(this.treeView1,currentNode.Tag.ToString());
}
}
else
{
this.toolTip1.SetToolTip(this.treeView1,"");
}
}


Hope this helps.
--
Adrian Mascarenhas, Developer Division

This posting is provided "AS IS" with no warranties, and confers no rights.

Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which they
originated.
 
Back
Top