Context Menu on Treeview

2 posts, 0 answers
  1. Simon Vaughan
    Simon Vaughan avatar
    1 posts
    Member since:
    Sep 2009

    Posted 02 Oct 2009 Link to this post

    Is there a way I can show one context menu for a radtreeview node that has child nodes and another context menu on nodes that have no child nodes?

    I am pretty sure this will have to be done in Java and I am not a Jscript wizard.

    I have tried :

    <

     

    telerik:RadTreeView ID="RadTreeView1" Runat="server" Skin="Office2007" OnContextMenuItemClick="RadTreeView1_ContextMenuItemClick" >

     

     

    <ContextMenus>

     

     

    <telerik:RadTreeViewContextMenu Skin="Office2007" ID="MainContextMenu" runat="server" >

     

     

    <Items>

     

     

    <telerik:RadMenuItem Value="Expand" Text="Expand Descendants"></telerik:RadMenuItem>

     

     

    <telerik:RadMenuItem Value="Collapse" Text="Collapse"></telerik:RadMenuItem>

     

     

    </Items>

     

     

    </telerik:RadTreeViewContextMenu>

     

     

     

    </ContextMenus>

     

     

    </telerik:RadTreeView>

     


    and then on the treeview node bound event I am setting the contextmenuid per node.  This unfortunately has no effect and all nodes get this menu.

    Any help would be appreciated.


    Thanks,


    Si


  2. it-workz
    it-workz avatar
    22 posts
    Member since:
    Mar 2007

    Posted 02 Oct 2009 Link to this post

    Hi,

    I have solved this scenario this way:

    configure 2 context menus:
     <telerik:RadTreeView ID="RadTreeView1" runat="server" Skin="Sunset" EnableDragAndDrop="True" 
                            EnableDragAndDropBetweenNodes="True" AllowNodeEditing="True" OnClientContextMenuItemClicking="onClientContextMenuItemClicking" 
                            DataFieldID="ID" DataFieldParentID="ParentID" DataSourceID="SqlDataSource1" 
                            DataTextField="Titel" DataValueField="Tekstnr">  
                            <ContextMenus> 
                                <telerik:RadTreeViewContextMenu ID="MainContextMenu" runat="server">  
                                    <Items> 
                                        <telerik:RadMenuItem Value="Rename" Text="Hernoemen ..." ImageUrl="~/images/rename.gif" 
                                            PostBack="false">  
                                        </telerik:RadMenuItem> 
                                        <telerik:RadMenuItem Value="NewFolder" Text="Nieuw tekstblok" ImageUrl="~/images/12.gif">  
                                        </telerik:RadMenuItem> 
                                        <telerik:RadMenuItem Value="NewSubFolder" Text="Nieuw sub-tekstblok" ImageUrl="~/images/12.gif">  
                                        </telerik:RadMenuItem> 
                                        <telerik:RadMenuItem Value="Delete" Text="Verwijder tekstblok" ImageUrl="~/images/7.gif">  
                                        </telerik:RadMenuItem> 
                                    </Items> 
                                    <CollapseAnimation Type="none" /> 
                                </telerik:RadTreeViewContextMenu> 
                                <telerik:RadTreeViewContextMenu ID="MainContextMenu2" runat="server">  
                                    <Items> 
                                        <telerik:RadMenuItem Value="NewSubFolder" Text="Nieuw sub-tekstblok" ImageUrl="~/images/12.gif">  
                                        </telerik:RadMenuItem> 
                                    </Items> 
                                    <CollapseAnimation Type="none" /> 
                                </telerik:RadTreeViewContextMenu> 
                            </ContextMenus> 
                        </telerik:RadTreeView> 



    Use nodedatabound to assign a menu
        Protected Sub RadTreeView1_NodeDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles RadTreeView1.NodeDataBound  
            If e.Node.Nodes.Count = 0 Then 
                e.Node.ContextMenuID = "MainContextMenu" 
            Else 
                e.Node.ContextMenuID = "MainContextMenu2" 
            End If 
        End Sub 
Back to Top