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

Multiple Context Menus for a Treeview

3 Answers 49 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Som
Top achievements
Rank 1
Som asked on 16 Sep 2008, 06:21 PM
Can we have multiple context menus for a tree and open the relevant one based on the attributes of a node?

Thanks for your help
Som

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 17 Sep 2008, 09:20 AM
Hello Som,

You need to create your ContextMenus and then assign the appropriate ContextMenuID to every node depending on its attribute. A similar scenario is shown here:
Context Menus > Creating Context Menus at Runtime

I hope this helps.

Kind regards,
Veskoni
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Shinu
Top achievements
Rank 2
answered on 17 Sep 2008, 11:44 AM
Hi Som,

You can also try the following javascript code to set the context menu depending on the node text.

ASPX:
<telerik:RadTreeView ID="RadTreeView1"    runat="server" OnClientContextMenuShowing="MenuShowing"   > 
           <Nodes> 
                        <telerik:RadTreeNode runat="server"     Text="Island"  Expanded="true" AllowDrag="false" 
                            AllowDrop="false"
                            <Nodes> 
                                <telerik:RadTreeNode runat="server" Text="Zanzibar" AllowDrag="false"
                                   .................. 
                             

<telerik:RadContextMenu ID="RadContextMenu1" runat="server"  > 
          <Items> 
            <telerik:RadMenuItem Text="ContextMenu1"></telerik:RadMenuItem> 
          </Items> 
        <Targets > 
           <telerik:ContextMenuControlTarget ControlID="RadTreeView1"  />  
        </Targets> 
      </telerik:RadContextMenu> 
         
        <telerik:RadContextMenu ID="RadContextMenu2" runat="server"
          <Items> 
            <telerik:RadMenuItem Text="ContextMenu2"></telerik:RadMenuItem> 
          </Items> 
          <Targets > 
           <telerik:ContextMenuControlTarget ControlID="RadTreeView1"  /> 
         </Targets> 
        </telerik:RadContextMenu> 


JS:
 <script  language="javascript" type="text/javascript"
      function MenuShowing(sender, eventArgs) 
      { 
       var node = eventArgs.get_node();  
       var  textnode.get_text(); 
       var contextMenu1 = $find("<%=RadContextMenu1.ClientID %>"); 
        var contextMenu2 = $find("<%=RadContextMenu2.ClientID %>"); 
        var evt = eventArgs.get_domEvent();   
        if(text=="Island") 
        { 
                contextMenu1.show(evt);  
                 
        } 
        if(text=="Zanzibar") 
        { 
         contextMenu2.show(evt); 
        } 
      } 
 </script> 


Thanks
Shinu.
0
Som
Top achievements
Rank 1
answered on 17 Sep 2008, 01:36 PM
thanks both of you
Tags
TreeView
Asked by
Som
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Shinu
Top achievements
Rank 2
Som
Top achievements
Rank 1
Share this question
or