RadTreeView Delete Child Nodes

4 posts, 0 answers
  1. Mouse
    Mouse avatar
    26 posts
    Member since:
    Sep 2009

    Posted 17 Sep 2009 Link to this post

    Hi,
     
    I have a radtree which I want to delete nodes on the click of a context menu. Here is what my treeview looks like:

    ...item1     ----> on right click of this node i have a context menu with the option "Clear"
    ......item1.1
    ......item1.2
    .........item1.2.1
    ...item2
    ...item3

    Once the "Clear" option is pressed i would like the tree to delete all the nodes under "item1". Leaving the RadTree looking like the following:

    ...item1
    ...item2
    ...item3

    How would i do this?
    Thanks
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 17 Sep 2009 Link to this post

    Hi,

    Try the following client side code in order to achieve the functionality.

    JavaScript:
     
     
    <script type="text/javascript"
    function onClientContextMenuItemClicking(sender, args) 
        var menuItem = args.get_menuItem(); 
        var treeNode = args.get_node(); 
        switch(menuItem.get_text()) 
        { 
            case "clear"
                var count = treeNode.get_nodes().get_count(); 
                for(var i =0 ; i< count; i++) 
                { 
                    treeNode.get_nodes().remove(treeNode.get_nodes().getNode(0));                 
                }             
                 
                break;     
            . . .                                    
        } 
    </script> 

    -Shinu.
  3. Mouse
    Mouse avatar
    26 posts
    Member since:
    Sep 2009

    Posted 17 Sep 2009 Link to this post

    Sorry I'm a bit of a novice and even more when it comes to JavaScript. Would i just put this into the head of the document?

    Thanks
  4. Mouse
    Mouse avatar
    26 posts
    Member since:
    Sep 2009

    Posted 17 Sep 2009 Link to this post

    Thanks Shinu I managed to solve it server side. Here is how i did it.

    protected void RadTreeView2_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)
    {
            RadTreeNode clickedNode = e.Node;

            case "Clear":
                    int count = clickedNode.Nodes.Count;
                    for (int i = 0; i < count; i++)
                    {
                        clickedNode.Nodes.RemoveAt(0);
                    }                
                    break;
    }

    Thank you very much I have a feeling that your code on the client side might come in use one day.
Back to Top