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

6 posts, 1 answers
  1. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 30 Jun 2010 Link to this post

    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....

  2. Tina Stancheva
    Admin
    Tina Stancheva avatar
    3299 posts

    Posted 01 Jul 2010 Link to this post

    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
  3. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 01 Jul 2010 Link to this post

    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
  4. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 02 Jul 2010 Link to this post

    Any ideas?
    thanks again
  5. Answer
    Miro Miroslavov
    Admin
    Miro Miroslavov avatar
    588 posts

    Posted 02 Jul 2010 Link to this post

    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
  6. Jon
    Jon avatar
    539 posts
    Member since:
    Apr 2004

    Posted 03 Jul 2010 Link to this post

    Thanks again
Back to Top