I have a Combobox that is using a tree view for the selectable items. The tree view is populated dynamically from database with load on demand using a web service.
The hierarchy of the tree view is arranged much like a file explorer, with files and folders.
I do not want to allow the user to select a folder, but only a file. I have added attributes to each node to set the proper image icon to be a folder or a file, etc.
How can I disable clicking on a node that has an attribute that indicates it is a folder?
Greg
The hierarchy of the tree view is arranged much like a file explorer, with files and folders.
I do not want to allow the user to select a folder, but only a file. I have added attributes to each node to set the proper image icon to be a folder or a file, etc.
How can I disable clicking on a node that has an attribute that indicates it is a folder?
Greg
3 Answers, 1 is accepted
0
Shinu
Top achievements
Rank 2
answered on 23 Nov 2009, 07:46 AM
Hi Greg,
It is possible to cancel the node clicking by attaching the OnClientNodeClicking event and executing the set_cancel(true) method. Tryout checking the attribute value in this event handler in order to cancel the nodeclicking event and see whether it helps.
JavaScript:
I am not sure about how you are adding the attributes to nodes. Could you provide some more information about this, if this does not help?
-Shinu.
It is possible to cancel the node clicking by attaching the OnClientNodeClicking event and executing the set_cancel(true) method. Tryout checking the attribute value in this event handler in order to cancel the nodeclicking event and see whether it helps.
JavaScript:
| <script type="text/javascript"> |
| function OnClientNodeClicking(sender, args) |
| { |
| if(args.get_node().get_attributes().getAttribute("condition") == "folder") |
| { |
| args.set_cancel(true); |
| } |
| } |
| </script> |
I am not sure about how you are adding the attributes to nodes. Could you provide some more information about this, if this does not help?
-Shinu.
0
Greg
Top achievements
Rank 1
answered on 23 Nov 2009, 02:31 PM
This does prevent it from being selected, however, it also closes the combo box. Is there a method to keep the combo box from closing? In essence, forcing the user to select a selectable node, or to close it explicitly?
This also seems to cause the expand node click to fail. The web service is called, and nodes are returned, but the node is never populated.
Also, it doesn't seem to work the first time I click a "clickable" node. It closes the combo box with nothing selected. I have to open it again and click it a second time before it takes.
Greg
Here's the code I am using to set attributes on each node as they are added.
Here is my javascript for OnNodeClientClicking
This also seems to cause the expand node click to fail. The web service is called, and nodes are returned, but the node is never populated.
Also, it doesn't seem to work the first time I click a "clickable" node. It closes the combo box with nothing selected. I have to open it again and click it a second time before it takes.
Greg
Here's the code I am using to set attributes on each node as they are added.
| protected void LoadTemplateNodes() |
| { |
| RadTreeView RadTreeViewTemplates = RadComboBoxTemplate.Items[0].FindControl("RadTreeViewTemplates") as RadTreeView; |
| var templates = IdeaStar.CreataSphere.TemplateUtilities.GetActiveTemplates(this.SitePage.Sites_ID, this.SitePage.Type); |
| if (templates.Count() > 0) |
| { |
| foreach (var template in templates) |
| { |
| RadTreeNode newNode = new RadTreeNode(template.Name, template.ID.ToString()); |
| newNode.AllowDrag = true; |
| newNode.AllowEdit = true; |
| newNode.Attributes["TemplateType"] = template.Type; |
| newNode.Attributes["PageType"] = this.SitePage.Type; |
| switch (template.Type) |
| { |
| case "P": |
| newNode.ImageUrl = "images/layout.png"; |
| break; |
| case "D": |
| newNode.ImageUrl = "images/database.png"; |
| break; |
| case "F": |
| newNode.ImageUrl = "images/folder.png"; |
| break; |
| } |
| if (IdeaStar.CreataSphere.TemplateUtilities.GetActiveTemplates(this.SitePage.Type, template.ID).Count > 0) |
| newNode.ExpandMode = TreeNodeExpandMode.WebService; |
| RadTreeViewTemplates.Nodes.Add(newNode); |
| } |
| } |
| } |
Here is my javascript for OnNodeClientClicking
| function nodeTemplateClicking(sender, args) { |
| var comboBox = $find("<%= RadComboBoxTemplate.ClientID %>"); |
| var node = args.get_node() |
| var attributes = node.get_attributes(); |
| var t = attributes.getAttribute("TemplateType"); |
| if (t == "F") { |
| args.set_cancel(true); |
| return; |
| } |
| comboBox.set_text(node.get_text()); |
| comboBox.trackChanges(); |
| comboBox.get_items().getItem(0).set_value(node.get_text()); |
| comboBox.commitChanges(); |
| comboBox.hideDropDown(); |
| } |
0
Hi Greg,
Greetings,
Simon
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Please call the StopPropagation function after canceling the NodeClicking event:
function StopPropagation(e){ //cancel bubbling e.cancelBubble = true; if (e.stopPropagation) { e.stopPropagation(); }} function OnClientNodeClicking(sender, args) { if(args.get_node().get_attributes().getAttribute("condition") == "folder") { args.set_cancel(true); StopPropagation(args.get_domEvent()); } }Greetings,
Simon
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.