TreeView Question

  • Thread starter Thread starter sianan
  • Start date Start date
S

sianan

Hi,

I want to display a 'hover box' (for want of a better description) when

the mouse hovers over a node in a tree view. The box would display
detail information for the node. It should be small, something like a
tool tip.


Does anyone have any idea of how to do this? I would really appreciate
any assistance, especially a code snippet or two.


Thanks!


~ Si
 
Handle the NodeMouseHover event of the TreeView. It contains arguments that
indicate which node is being hovered over. Then all you have to do is
implement a ToolTip (or rool your own), and display it wherever you want to,
in whatever way you want to.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
 
Thanks Kevin,

I still can't make it work though. Not sure how I should implement the
ToolTip and associate it with the selected node. Here's what I've got:

private void myTreeView_NodeMouseHover(object sender,
TreeNodeMouseHoverEventArgs e)
{
e.Node.ToolTipText = "description";

}

Something is obviously missing (just can't figure it out).

Thanks!
 
Hi sianan,

If you set the TreeView's ShowNodeToolTips property to true, you don't even
have to handle the OnMouseOver event if you only want to display a ToolTip
on a TreeNode when the mouse hovers over it. Just set the node's ToolTipText
property. However, if you want to dynamically assign the ToolTipText when
the Mouse hovers over the TreeNode, this will be much more difficult. The
ToolTip will pop up before the event is fired, and the text assigned will be
the text that was assigned prior to the event.

Now, I haven't tested this, but I believe it would be possible to handle the
TreeView.MouseMove event to do this. The trick is getting the TreeNode that
the mouse is over. This is done using the TreeView.HitTest method. When the
MouseMove event fires, it passes a MouseEventArgs argument to the event
handler. This contains the XY coordinates of the mouse relative to the
Control. You can take the X and Y values and pass them to the
TreeView.HitTest method, which returns a TreeViewHitTestInfo instance that
contains the TreeNode that the mouse is over (if any). You can use this to
get a handle on the TreeNode and assign the ToolTipText prior to the
MouseHover event, which happens only when the moust *stops* moving over a
Control for a period of several milliseconds. Then, assuming you've turned
on the ShowNodeToolTips property, you shouldn't have to handle any other
events.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
 
Back
Top