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

dynamic context menus

3 Answers 80 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 01 May 2009, 09:48 PM
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.

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 04 May 2009, 09:43 AM
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.
0
James
Top achievements
Rank 1
answered on 04 May 2009, 02:15 PM
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.
0
Accepted
Atanas Korchev
Telerik team
answered on 04 May 2009, 02:29 PM
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.
Tags
TreeView
Asked by
James
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
James
Top achievements
Rank 1
Share this question
or