dynamic context menus

4 posts, 1 answers
  1. James
    James avatar
    5 posts
    Member since:
    Apr 2009

    Posted 01 May 2009 Link to this post

    I have a question about how I should handle context menu generation. I'm including my treeview aspx below:

     

    <telerik:RadTreeView ID="RadTreeView1"   
                                    Runat="server"   
                                    EnableDragAndDrop="True"   
                                    EnableDragAndDropBetweenNodes="True"   
                                    OnNodeDrop="RadTreeView_HandleDrop"   
                                    OnClientNodeDropping="onNodeDropping"   
                                    MultipleSelect="True" 
                                    OnClientNodeDragging="onNodeDragging"   
                                    AllowNodeEditing="True" 
                                    OnContextMenuItemClick="RadTreeView_ContextMenuItemClick" 
                                    OnClientContextMenuItemClicking="onClientContextMenuItemClicking" 
                                    OnNodeDataBound="RadTreeView_OnNodeDataBound" 
                                    OnClientContextMenuShowing="onClientContextMenuShowing" 
                                    OnNodeEdit="RadTreeView_NodeEdit" 
                                    DataTextField="Text">  
                            <ContextMenus> 
                                <telerik:RadTreeViewContextMenu ID="PartMenu" runat="server">  
                                    <Items> 
                                        <telerik:RadMenuItem Value="Copy" Text="Copy Part" /> 
                                        <telerik:RadMenuItem Value="Edit" Text="Edit Part" /> 
                                        <telerik:RadMenuItem Value="Delete" Text="Delete Part" /> 
                                        <telerik:RadMenuItem Value="Properties" Text="Properties" /> 
                                    </Items> 
                                </telerik:RadTreeViewContextMenu> 
                                <telerik:RadTreeViewContextMenu ID="SectionMenu" runat="server">  
                                    <Items> 
                                        <telerik:RadMenuItem Value="Add" Text="Add Category" /> 
                                    </Items> 
                                </telerik:RadTreeViewContextMenu> 
                                <telerik:RadTreeViewContextMenu ID="CategoryMenu" runat="server">  
                                    <Items> 
                                        <telerik:RadMenuItem Value="Add" Text="Add Subcategory" /> 
                                        <telerik:RadMenuItem Value="Delete" Text="Delete Subcategory" /> 
                                        <telerik:RadMenuItem Value="Properties" Text="Properties" /> 
                                    </Items> 
                                </telerik:RadTreeViewContextMenu> 
                                <telerik:RadTreeViewContextMenu ID="SubCategoryMenu" runat="server">  
                                    <Items> 
                                        <telerik:RadMenuItem Value="Delete" Text="Delete Subcategory" /> 
                                        <telerik:RadMenuItem Value="Properties" Text="Properties" /> 
                                    </Items> 
                                </telerik:RadTreeViewContextMenu> 
                            </ContextMenus>     
                        </telerik:RadTreeView> 

     



    What I am trying to do is use those seperate context menus based on the level of the selected node. Basically limiting options on certain level nodes. I have tried numerous ways to get this to work and nothing has so far. It just displays the first context menu all the time.


    I'm trying to handle the changes in this javascript method:

    function

     

    onClientContextMenuShowing(sender, args)

     



    Is that even the correct event to handle it in? I don't really see any other choices.

    Essentially I am just trying to do a switch on the selectedNode.LevelID which is an attribute that is 1-4 depending on the depth of the node.

    Are there any examples anywhere? I have spent all day searching and trying to get this to work to no avail.
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 04 May 2009 Link to this post

    Hi James,

    I may suggest you use the ContextMenuID property of the nodes to specify the context menu for them. I have attached a sample page to demonstrate my idea.

    Regards,
    Albert
    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.
  3. James
    James avatar
    5 posts
    Member since:
    Apr 2009

    Posted 04 May 2009 Link to this post

    That would work if I wasn't dynamically building the treeview from an xmldatasource. What I need is this for this to be able to adapt to any situation. For instance.. the root node isn't always going to be level 1.... sometimes it might be level 2 or maybe 3. So I really need to handle this in the javascript do I not?

     switch(treeNode.LevelID)  
                    {  
                        
                        // section  
                        case "1":  
                          
                          <%= SectionMenu.ClientID %>.ContextMenuID = SectionMenu.ID;  
     
                          break;   
     
                        // category  
                        case "2":  

    I've been trying something like that... although I'm not sure that is going to work either. I cannot get VS to stop at a breakpoint anywhere in this function.
  4. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 04 May 2009 Link to this post

    Hi James,

    I am afraid this cannot be achieved on the client-side. I suggest you traverse the nodes after databinding (use the DataBound event of the treeview) and assign the property ContextMenuID property.

    Regards,
    Albert
    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.
Back to Top