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

Mutiple Select with ContextMenu

2 Answers 100 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Ryan Abbott
Top achievements
Rank 1
Ryan Abbott asked on 20 Jan 2009, 11:24 PM
I'm running into an issue with the ContextMenu where I need to select multiple nodes and use a context menu to apply an action to all those selected nodes. For example: I want to select 3 nodes for deletion, so I select the 3 nodes holding down CTRL, and then I right click on the node and the context menu appears. However, only the node that I right click is selected, the others are no longer selected. I found that when holding CTRL and selecting the first 2 nodes, then right-clicking the 3rd node while holding CTRL, it will select all 3 nodes.

I'm not doing autopostbacks, this is all contained client-side until they select an option (Add,Delete - took out that code here for space)

Javascript:
function ShowContextMenu(node, e) 
        {    
            var menu = null;   
            var item = null;                                 
            var selectedNodes = null
            menu = window["<%= RadMenu1.ClientID %>"]; 
            menu.ContextMenuElementID = node.TreeView.ClientID; 
            treeView = node.TreeView; 
            selectedNodes = treeView.GetSelectedNodes(); 
                         
            var sNodes = "Selected Node Count: " + selectedNodes.length + "\r\n"
            for(i=0;i<selectedNodes.length;i++) 
                sNodes+= selectedNodes[i].Text + ", "
            alert(sNodes); 
             
            if (menu) 
            {    
                menu.Show(e);                 
                e.cancelBubble = true
                if (e.stopPropagation) 
                { 
                    e.stopPropagation(); 
                } 
                e.returnValue = false
                if (e.preventDefault) 
                { 
                    e.preventDefault(); 
                } 
            } 
        } 
 
function OnClick(sender, eventArgs) 
        { 
            var menu = null;                         
            var selectedNodes = null
            menu = window["<%= RadMenu1.ClientID %>"];             
            treeView = window[ menu.ContextMenuElementID ];    
            selectedNodes = treeView.GetSelectedNodes(); 
             
            alert("Nodes Selected: " + selectedNodes.length); 
            return true
        } 
 
 

HTML:
<radT:RadTreeView ID="rtEntitlementPages" OnNodeDrop="rtEntitlementPages_NodeDrop" 
                runat="server" DataTextField="Title" DataFieldID="PageId" DataFieldParentID="ParentPageId"  
                DataValueField="PageId" DragAndDrop="true" DragAndDropBetweenNodes="true" MultipleSelect="true" 
                BeforeClientContextMenu="ShowContextMenu"
            </radT:RadTreeView> 
            <radm:RadMenu ID="RadMenu1" runat="server" IsContext="True" OnClientItemClicking="OnClick" 
                ContextMenuElementID="none" SkinID="TreeContextMenu" OnItemClick="RadMenu1_ItemClick" meta:resourcekey="RadMenu1Resource1"
                <Items> 
                    <radm:RadMenuItem ID="RadMenuItem1" Text="Add" Value="Add" runat="server" meta:resourcekey="RadMenuItemAddResource" /> 
                    <radm:RadMenuItem ID="RadMenuItem3" Text="Delete" Value="Delete" runat="server" meta:resourcekey="RadMenuItemDeleteResource" /> 
                </Items> 
            </radm:RadMenu> 

2 Answers, 1 is accepted

Sort by
0
Accepted
Yana
Telerik team
answered on 23 Jan 2009, 08:31 AM
Hi Ryan,

It seems that you're using RadTreeView for ASP.NET so I moved the forum thread to the right place.

Please add the javascript function from the attached file to your page in order to fix this issue with RadTreeView and RadMenu.

Regards,
Yana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Ryan Abbott
Top achievements
Rank 1
answered on 23 Jan 2009, 04:29 PM
Thank you for you help! I had to put this in the top of my ShowContextMenu() function in order for it to work correctly, but I can now do multiple selects with the context menu capturing all of them.

Thanks!
-Ryan
Tags
TreeView
Asked by
Ryan Abbott
Top achievements
Rank 1
Answers by
Yana
Telerik team
Ryan Abbott
Top achievements
Rank 1
Share this question
or