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

dynamic RadTreeContextMenu not activating

1 Answer 51 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Phillip
Top achievements
Rank 1
Phillip asked on 04 Jun 2012, 04:16 AM
I have a content page that contains a RadSplitter.  On the left of the splitter is a RadPane with a Radtreeview. the treeview definition is below.

<telerik:RadTreeView ID="rtOutline"
                        runat="server" AccessKey="w"  CausesValidation="False"
                        EnableDragAndDrop="True"  EnableDragAndDropBetweenNodes="True"
                        EnableViewState="True"
                        CollapseAnimation-Type="None"
                        ExpandAnimation-Type="None" OnNodeExpand="rtOutline_NodeExpand" >
                <ContextMenus>
                    <telerik:RadTreeViewContextMenu ID="ElementMenu" runat="server"  EnableAutoScroll="True">
                    </telerik:RadTreeViewContextMenu>
                </ContextMenus>
                <ExpandAnimation Type="None" />
            </telerik:RadTreeView>

As you can see I have subscribed to the Node Expand event of the server side.  There is a lot of node building code in here so I won't post it all. however a single child node is successfully created (See image nodeDetail.gif). This image shows the Id from the menu
Protected Sub rtOutline_NodeExpand(sender As Object, e As Telerik.Web.UI.RadTreeNodeEventArgs) Handles rtOutline.NodeExpand
    Dim newNode As RadTreeNode = NodeControl.LoadNodes(e.Node, rtOutline)
    e.Node = newNode
 
End Sub

The RadTreeContextMenu is also generated. See attachment MenuDetail.gif this image shows the detail of the menu including the fact that it has childitems.

The process is 
  • The node is generated
  • the node id is passed into a function to generate the RadTreeContextMenu  
    and the menu is returned.
  • the menu is added to the RadTreeView
  • the menu Id is assigned to the contextrmenuid property
  • the node is then added to its parent.
Dim nodeMenu As RadTreeViewContextMenu = myMenuBuilder.BuildMenu(targetNode)
nodeTreeview.ContextMenus.Add(nodeMenu)
targetNode.ContextMenuId = nodeMenu.ID

  • the parent is returned to the controlling function and attached to the tree

When I run this the new node shows perfectly but the menu does not.  It shows the standard IE Context menu See result.gif.

The code for building the menu is
Public Function BuildMenu(ByVal myNode As RadTreeNode) As RadTreeViewContextMenu
 
        Dim myMenu As New RadTreeViewContextMenu
        Dim menuElements As List(Of ElementWrapper) = LoadElements(myNode.Attributes("IID"))
        Dim helpItem As New RadMenuItem
        Dim iLoopCounter As Int32 = 0
 
        '***** Loading Menu Item
        Dim mnuLoading As New RadMenuItem
        mnuLoading.Text = "Loading..."
        mnuLoading.Enabled = False
 
        myMenu.Items.Add(mnuLoading)
 
        For Each a As ElementWrapper In menuElements
 
            Dim newMenuItem As New RadMenuItem
            newMenuItem.Text = a.Text
            newMenuItem.EnableImageSprite = a.Enabled
            newMenuItem.Attributes.Add("Command", a.Cmd)
            newMenuItem.Attributes.Add("CommandArg", a.CmdArg)
            newMenuItem.Attributes.Add("IID", myNode.Attributes("IID"))
 
            If a.Cmd = "HELP_MENU" Then
 
                helpItem = newMenuItem
                Dim aSplitter = New RadMenuItem
                aSplitter.IsSeparator = True
 
                Dim myStyle As New Style
                myStyle.Width = Unit.Pixel(125)
 
                aSplitter.ApplyStyle(myStyle)
                myMenu.Items.Add(aSplitter)
 
            ElseIf a.Cmd = "HELP_ITEM" Then
                helpItem.Items.Add(newMenuItem)
            Else
                myMenu.Items.Add(newMenuItem)
            End If
 
            iLoopCounter = iLoopCounter + 1
 
        Next
 
        Dim newHeight As Int32 = iLoopCounter * 25
        If newHeight > 250 Then newHeight = 250
 
        myMenu.AutoScrollMinimumHeight = newHeight
        myMenu.ID = "mnu" & myNode.Attributes("IID")
        myMenu.EnableViewState = True
        myMenu.ClientIDMode = ClientIDMode.Static
 
        Return myMenu
 
    End Function

I have tried this with and without the view state set and the ClientIDMode and still cannot get it to show,

Questions (in order of priority)
  1. Can you please advise why the menu would not activate?
  2. Why would the menu not be maintained if the viewstate is enabled.  this happens if I click on the node after it has been generated

1 Answer, 1 is accepted

Sort by
0
Accepted
Plamen
Telerik team
answered on 06 Jun 2012, 02:03 PM
Hello Philip,

 
I have tested a similar scenario by adding the following code to the code from this help topic:

Protected Sub RadTreeView1_NodeExpand(sender As Object, e As RadTreeNodeEventArgs)
    Dim a As New RadTreeNode("Added Node")
    e.Node.Nodes.Add(a)
End Sub

It worked properly and showed the dynamic created menu on the newly added node. Please elaborate a little bit how is you scenario different so we can be more helpful.

Regards,
Plamen Zdravkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
TreeView
Asked by
Phillip
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Share this question
or