Can you add a button to a treeview node?
I need to give my client the ability fire an event on a specific node, but nice I have various other functionality tied into the tree already I don't really want to add a button below the tree to provide this event.
So... Can I have a node like this.
Node Text - (Button)
When the user clicks a button next to the node it fires off an event. Maybe the button would select the node so I could get the info off the node tag.
Let me know.
~Mike
6 Answers, 1 is accepted
Thank you for writing. Please specify exactly what is your case. What kind of event do you need? Maybe we can add this event directly in RadTreeView in future. I have the feeling that you can proceed fine without a button. I am looking forward to your reply.
Best wishes,
Victor
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Let me setup the screen for you…
The user is presented a list of documents in a treeview. They can re-order the documents via drag & drop (one or many), delete them from the list (one or many), or denote them as a special document type (one or many – special type also changes the node icon).
Each one of these functionalities are currently being handled via buttons below the treeview. So if the user decides to re-order they would update the DB via the update order button. If they want to delete one or several documents they select the item(s) and click the delete button (updates DB). If they want to denote the document as a special type they select one or several and click the type button (updates DB).
With the new requested functionality the user wanted to have an ‘edit’ button next to a specific document type that meet certain criteria. IE: Only document types of ‘endorsement’ that are in ‘released’ status would see an edit button next to the node.
When the user clicks the ‘edit’ button we do a bunch of magic that would remove the current document, and replace it with a new document with a status of ‘work in progress’.
Now, with that said, I could easily add another button below the treeview that would handle this functionality – figure out what node was selected, remove it, add a new node, and do the document creation process. But, if there was a way to add a button next to the node text it would save me a lot of checking to see if the node is the correct document type and status, before I process. Also, it would also stop me from having to check if they selected many documents – this functionality can only be performed on one document at a time.
I hope I made myself clear.
~Mike
Thank you for the in-depth explanation. In order to place a button next to the nodes, you will have to inherit RadTreeView and modify its layout. But that will be hard to do so I suggest creating a context menu for each node and adding options in it depending on your criteria. Here is how you can associate a context menu to a RadTreeNode. The first node in this example:
RadDropDownMenu menu = new RadDropDownMenu(); |
menu.Items.Add(new RadMenuItem("Action1")); |
menu.Items.Add(new RadMenuItem("Action2")); |
menu.Items.Add(new RadMenuItem("Action3")); |
this.radTreeView1.Nodes[0].ContextMenu = menu; |
The only thing left to do is to subscribe to the Click event of each menu item and perform the needed actions. Also if you want to disable a menu item you have to set its Enabled property to false. Do not hesitate to write back if you need further assistance.
Sincerely yours,
Victor
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
i have to add Button to each node in the Tree view. if i click the button,i have to open popup using Radwindow. Please give an idea how to add Button to each node.
Thanks and Regards,
Srikanth.
Thank you for writing.
As I stated in my previous post RadTreeView does not support custom elements in its nodes, your best bet is to use a context menu that is specific for each node.
Write again if you have other questions.
Victor
the Telerik team
Please note that in Q1 2011 we have introduced a major upgrade of RadTreeView control, which is now virtualized and fully customizable. Feel free to download the latest release and try it out. For more information on our latest release refer to this blog post.
Best wishes,
Stefan
the Telerik team