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

Context Menu - How to limit 'opening' only certain nodes

5 Answers 50 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 30 Jun 2010, 07:04 PM
Hi..
I have treeview with  4 branches  (will never have more)

ROOT
   -- CUSTOMERS
       --  PRODUCTs
            ----  CATEGORY

I only want to enable the context menu if they select PRODUCTS or CATEGORY.

Any ideas ? thanks again....

5 Answers, 1 is accepted

Sort by
0
Tina Stancheva
Telerik team
answered on 01 Jul 2010, 08:18 AM
Hello Jon,

You can define a different DataTemplate for each level of the tree - thus declaring different templates for the separate types of data items. Then you can define a ContextMenu only in the Products and Categories DataTemplates. For example the Products DataTemplate can be defines as:
<telerik:HierarchicalDataTemplate x:Key="ProductsTemplate" >
    <TextBlock Text="{Binding Name}">
        <telerikNavigation:RadContextMenu.ContextMenu>
            <telerikNavigation:RadContextMenu Opened="RadContextMenu_Opened">
                <telerikNavigation:RadMenuItem Header="Item1" />
                <telerikNavigation:RadMenuItem Header="Item2" />
            </telerikNavigation:RadContextMenu>
        </telerikNavigation:RadContextMenu.ContextMenu>
    </TextBlock>
</telerik:HierarchicalDataTemplate>
Give this approach a try and let me know if it works for you.

However, if your scenario requires a different approach or you need more info, please let us know.

Sincerely yours,
Tina Stancheva
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jon
Top achievements
Rank 1
answered on 01 Jul 2010, 03:58 PM
Hi..
The treeview is programmatically generated.
How can I determine the branch?  I only want the context menu on branch 3 and 4
thanks again
0
Jon
Top achievements
Rank 1
answered on 02 Jul 2010, 02:07 PM
Any ideas?
thanks again
0
Accepted
Miro Miroslavov
Telerik team
answered on 02 Jul 2010, 03:56 PM
Hi Jon,

Since you generate the RadTreeViewItems in the code-behind, you can check if you are about to create "branch 3 or 4" item just attach a ContextMenu to it.

RadTreeViewItem newItem = new RadTreeViewItem();
//initialize it here.
 
//Check if the newItem should have ContextMenu?
//Then
RadContextMenu menu = new RadContextMenu();
//add MenuItems here
RadContextMenu.SetContextMenu(newItem , menu);

If you have further questions, please ask us.

Sincerely yours,
Miro Miroslavov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Jon
Top achievements
Rank 1
answered on 03 Jul 2010, 03:09 PM
Thanks again
Tags
TreeView
Asked by
Jon
Top achievements
Rank 1
Answers by
Tina Stancheva
Telerik team
Jon
Top achievements
Rank 1
Miro Miroslavov
Telerik team
Share this question
or