Question : Tooltips in .Net treeview

Hi,

I have a treeview (.net control) in one application but I would like to add the possibility that  the user could show or hide the tooltips on the different nodes of the treeview.  Currently, the tooltips seem to be generate automatically and I can't find a way to hide them.  Some of them are pretty long and I don't want to show them.

Is there a way, with a button that a user could press, to hide or show all the tooltips on a .net treeview?

Thanks for your help,

Eric

Answer : Tooltips in .Net treeview

Xedom

No, that isn't a tooltip. That's a popup that shows all the text, which will only appear when the text of the treenode is not entirely visible.

What you can do is set the ToolTipText of each node to something much shorter, say the first 50 characters, and use the code I posted above to toggle which 'type' of tooltip you'd like to show (long or short).

Use this routine to set the tooltip to something shorter....

    Public Sub SetNodeToolTips(ByRef nd As TreeNode)
        nd.ToolTipText = nd.Text.Substring(0, Math.Min(nd.Text.Length, 50)) & "..."
        For Each n As TreeNode In nd.Nodes
            n.ToolTipText = n.Text.Substring(0, Math.Min(n.Text.Length, 50)) & "..."
        Next
    End Sub

...and use it like this in the Form.Load() event....

    For Each n As TreeNode In TreeView1.Nodes
        SetNodeToolTips(n)
    Next

Wayne
Random Solutions  
 
programming4us programming4us