This is a migrated thread and some comments may be shown as answers.

[Solved] Using RadContextMenu with RadTreeView

3 Answers 294 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ross Wozniak
Top achievements
Rank 1
Ross Wozniak asked on 09 Jul 2009, 06:35 PM
I'm trying to add basic context menu support to my RadTreeView and am having difficulty not only figuring out how to do it, but also cannot find RadContextMenu info in your Help documentation.

My scenario is pretty basic. When the user right-clicks on the RadTreeView I want to show the context menu and only show items that are appropriate for that node. So let's say I have two nodes, and want one context menu item to show when right-clicking on the first node and the other item to show when clicking on the second.

It appears that you don't currently support the ability to associate multiple context menus with a tree view, so I suppose what I have to do is, when right-clicking, figure out which node was right-clicked on and set the visibility of the context menu items at that point.

The code in your Silverlight samples browser (http://demos.telerik.com/silverlight/#ContextMenu/FirstLook) has an event handler for the Opened event that sets the IsEnabled property for various items, so I'm guessing I could do it in this way (seems strange...shouldn't the event be called Opening instead of Opened?) but the code in the samples browser accesses the right-clicked node by calling GetClickedElement on the RadContextMenu. However, I tried this but I don't see that method on that object...even in the latest Q2 SL3 build.

Any help (or a pointer to any Help documentation) would be appreciated!

Thanks,
Ross

3 Answers, 1 is accepted

Sort by
0
Tihomir Petkov
Telerik team
answered on 10 Jul 2009, 11:56 AM
Hi Ross,

Please take a look at the following blog post which explains how to attach a context menu to RadTreeView control:

http://blogs.telerik.com/valerihristov/posts/09-04-27/attaching_a_contextmenu_on_a_treeview_with_radcontrols_for_silverlight.aspx

Let me know if you have any problems.

Greetings,
Tihomir Petkov
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.
0
Ross Wozniak
Top achievements
Rank 1
answered on 10 Jul 2009, 04:49 PM
I just downloaded the latest internal build for SL3, and can now call GetClickedElement on the context menu. You may want to add this null check to the code in your samples browser though so it doesn't throw an error when you right-click outside of a node:

 

var item = ContextMenu.GetClickedElement<RadTreeViewItem>();

 

 

if (item == null)

 

{

 

    return;

 

}

0
Tihomir Petkov
Telerik team
answered on 13 Jul 2009, 02:00 PM
Hi Ross,

Thank you for the suggestion, we will consider it in our next revision of the online examples. I updated your Telerik points.

Greetings,
Tihomir Petkov
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.
Tags
TreeView
Asked by
Ross Wozniak
Top achievements
Rank 1
Answers by
Tihomir Petkov
Telerik team
Ross Wozniak
Top achievements
Rank 1
Share this question
or