Open Context Menu On Node Drop

6 posts, 2 answers
  1. Adam Webb
    Adam Webb avatar
    8 posts
    Member since:
    Apr 2009

    Posted 07 Aug 2009 Link to this post

    Hi,

    I would like to be able to open a context menu when the Client-Side event "OnClientNodeDropped" is fired. From this I would like the user to be able to choose an item from the context menu. 
    So, server side I would like to get: 
    What choice was made on the context menu
    What is the destination node
    What is the source node

    I realise a similar question has been asked, (http://www.telerik.com/community/forums/aspnet-ajax/treeview/contextmenu-on-onnodedropping-event.aspx), however, this was posted more than a year ago. 
    Is there anyway to achieve this result? 

    Thank you for your time, 
    Adam
  2. Answer
    Yana
    Admin
    Yana avatar
    4993 posts

    Posted 12 Aug 2009 Link to this post

    Hi Adam,

    I've attached a simple page demonstrating the needed approach, please download it and give it a try.

    Kind regards,
    Yana
    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.
  3. Adam Webb
    Adam Webb avatar
    8 posts
    Member since:
    Apr 2009

    Posted 12 Aug 2009 Link to this post

    Thank you Yana.
    That's fantastic! 
    Exactly what I was hoping to accomplish.

    Kind Regards,
    Adam
  4. Adam Webb
    Adam Webb avatar
    8 posts
    Member since:
    Apr 2009

    Posted 13 Aug 2009 Link to this post

    Dear Yana,
    While the zip file you posted previously does work and is greatly appreciated, I have encountered a problem.

    It seems to be that once I add a NodeExpand event handler to the tree, the context menu stops showing up when the node is dropped (Or it seems as though it as about to show, and then disappears). 

    The Nodes are setup so that their expand mode is TreeNodeExpandMode.ServerSideCallBack

    Inside the NodeExpand event handler I am adding Child-Nodes to the node which has been expanded. For example something like this: 

    void RadTreeView1_NodeExpand(object sender, RadTreeNodeEventArgs e) 
            for (int i = 0; i < 5; i++) 
                { 
                    RadTreeNode node = new RadTreeNode(); 
                    node.Text = e.Node.Text + "." + i; 
                    node.Value = e.Node.Value + "." + i; 
    node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack; 
                    e.Node.Nodes.Add(node); 
                } 
    e.Node.ExpandMode = TreeNodeExpandMode.ClientSide; 
            e.Node.Expanded = true;  

    Thanks again for your time,
    Kind Regards,
    Adam
  5. Answer
    Yana
    Admin
    Yana avatar
    4993 posts

    Posted 14 Aug 2009 Link to this post

    Hi Adam,

    Thank you for getting back to me.

    Please modify nodeDropping function like this:

    <script type="text/javascript"
        function nodeDropping(sender, args) 
        { 
            args.set_cancel(true); 
            var menu = $find("<%=RadContextMenu1.ClientID %>"); 
            menu.trackChanges(); 
            menu.get_items().getItem(0).get_attributes().setAttribute("sourceNode", args.get_sourceNode().get_value()); 
            menu.get_items().getItem(0).get_attributes().setAttribute("destNode", args.get_destNode().get_value()); 
            menu.commitChanges(); 
            setTimeout( function() {menu.show(args.get_domEvent())}, 100); 
        } 
    </script> 

    I've also attached the modified page for a reference.

    Kind regards,
    Yana
    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.
  6. Adam Webb
    Adam Webb avatar
    8 posts
    Member since:
    Apr 2009

    Posted 14 Aug 2009 Link to this post

    Yana. Thank you! That's fantastic.
    Works like a charm. 

    Kind Regards,
    Adam
Back to Top