ASPX templates
Version 4.x > ASPX templates > Using Tooltips in CMSTreeView View modes: 
User avatar
Member
Member
Steve-Appetere - 8/4/2009 9:46:36 AM
   
Using Tooltips in CMSTreeView
Hello

I am using the CMSTreeView control on an ASPX page template to display a hierarchical menu of pages which a user can navigate too.

Most of my page names are very long, and overflow the <div> in which they are displayed, so I would like to populate the ToolTip with the Document Name of each.

I thought I would be able to intercept the TreeNodeDataBound event for the control, and set the ToolTip for each node there. However, when I tried this, the event never fires, so I am guessing Kentico populates the CMSTreeView programatically, rather than using data-binding?

Any ideas therefore how to set the ToolTip to the Document Name of each node in the tree?

Thank you,

Steve

User avatar
Kentico Developer
Kentico Developer
kentico_zbysekn - 8/4/2009 11:15:47 AM
   
RE:Using Tooltips in CMSTreeView
Hi Steve,
you can go through the treeview hierarchy and set every node tooltip property to its text property value, because its populated by documentmenucaption value and in case this value is empty or not set, documentname is used instead.
Best Regards,
Zbysek Nemec.

User avatar
Member
Member
Steve-Appetere - 8/4/2009 3:09:38 PM
   
RE:Using Tooltips in CMSTreeView
Thanks for the advice, but it doesn't seem to be quite as simple as that.

The TreeNode.Text property, for leaf nodes, actually contains all the markup required to display an icon & a hyperlink, so you would have to extract the text required from the middle of this.

A more difficult problem though is where to set the ToolTip?

If I am correct in my first post, then you cannot use TreeNodeDataBound, as the control is not databound.

You should be able to set ToolTips in the PreRender method, by iterating through the nodes visible when the TreeView is first rendered (the approach you suggest).

But as I have DynamicBehaviour = "true" the rest of the nodes are only populated as they are expanded.

So there is a further task, to set the ToolTips of nodes that are dynamically added.

When a node is expanded, the TreeNodePopulate event is run, but as far as I can tell, it runs before the nodes in the expanded branch are populated.

So the only way I can see to work round this is to subclass the CMSTreeView control, and override the TreeNodePopulate event so that the base behaviour happens first (populating the nodes) and then I can change the ToolTips for the new nodes.

But this all seem rather complicated, for what is presumably a fairly common requirement.

Can you think of a simpler method to do this that I am overlooking?

(I have also read about using JavaScript to intercept the mouse-over events of nodes and set the tool tip on the fly, but again, this seems a complicated approach).

Thanks,

Steve

User avatar
Member
Member
Steve-Appetere - 8/7/2009 7:32:05 AM
   
RE:Using Tooltips in CMSTreeView
I compromised in the end, and decided just to add tooltips to leaf nodes in the tree, so I only needed to override the TreeNodePopulate event.

In brief, I did this by deriving my own class from CMSTreeView and overriding the OnTreeNodePopulate method. It uses a Regular Expression to look for nodes that have an <a> (anchor) element in them, and extracts the text to use as a tool tip.

This is some of the code, if of interest.


protected override void OnTreeNodePopulate(TreeNodeEventArgs e)
{
base.OnTreeNodePopulate(e);

// Add ToolTips to the populated nodes

foreach (TreeNode childNode in e.Node.ChildNodes)
{
//Look for the text in <a ...>THIS TEXT</a>, if anchor exists
Match anchorTextMatch = Regex.Match(childNode.Text,@"<a.*>(.*)</a>$");

if (anchorTextMatch.Success)
{
childNode.ToolTip = HttpUtility.HtmlDecode( anchorTextMatch.Groups[1].Value);
}
}
}


Steve

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 8/10/2009 6:36:10 AM
   
RE:Using Tooltips in CMSTreeView
Hi Steve,

Unfortunately, there is no easier way in current version how to add tooltip to nodes. I've passed request to our Product Manager to add some support for this into one of future versions.

Thank you for your sample code for adding tooltip to leaf nodes.

Best Regards,

Martin Dobsicek

User avatar
Certified Developer 11
Certified Developer 11
jashut-gmail - 2/27/2012 8:31:06 PM
   
RE:Using Tooltips in CMSTreeView
Hi Stev,

thansk for the code, I am trying to do similar thing buy my override method doesn't fire.

How did you create control on aspx page using derived class? can you please bit more insight on how to get it working.

cheers
jash

User avatar
Kentico Developer
Kentico Developer
kentico_helenag - 3/5/2012 7:42:19 AM
   
RE:Using Tooltips in CMSTreeView
Hello,


you can contact Steve on their site: http://www.appetere.com/Blogs/SteveM.

I think he means that he created a new class like:

public class myNewClass : CMSTreeView

and then he overrides the OnTreeNodePopulate method.

I would recommend you the Consulting services: http://www.kentico.com/Support/Consulting/Overview The experienced solution architects can help you with the custom solution.


Best regards,
Helena Grulichova