TreeViewNode.ContextMenu in codebehind?

6 posts, 0 answers
  1. Kevin
    Kevin avatar
    1 posts
    Member since:
    Jun 2010

    Posted 27 Jun 2010 Link to this post

    Hi all,

    Apologies if this is a question answered elsewhere or if I've missed something simple.

    I've got a treeview in which I build the nodes dynamically based on a datasource - specifically I'm manually creating new RadTreeNodes and inserting them because I want different behaviours based on each, but that's probably not directly relevant. At the time of creating each node I assign it to a predefined (in the .aspx) RadContextMenu, like this:

    RadTreeNode contactNode = new RadTreeNode();  
    if (contact == currentCustomer.ContactAccounts)  
       contactNode.ImageUrl = "~/images/icons/16/user-business.png";  
    else 
       contactNode.ImageUrl = "~/images/icons/16/user-worker.png";  
    contactNode.Text = contact.Name;  
     
    if (contact.Email.Length > 0 && contact.Fax.Length > 0)  
    {  
       contactNode.ContextMenuID = "contactContextMenuEmailAndFax";  
    }  
    else if (contact.Email.Length > 0)  
    {  
       contactNode.ContextMenuID = "contactContextMenuEmailOnly";  
    }  
    ... etc etc etc 

    There are two things I'd like to do and haven't found a means of doing:

    1) rather than define 4 multiple menus including email, fax, email and fax and neither, it'd be nice to be able to iterate the collection of menuitems and simply disable the ones that don't matter

    2) I'd like to set the NavigateUrl property of the "Email contact" menu item to a mailto: link at render time


    Is there a way to do this?

    Cheers,

    Kev
  2. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 30 Jun 2010 Link to this post

    Hello Kevin,

    I prepared an example that should solve your problems.
    Here is the markup of the TreeView:

    <telerik:RadTreeView runat="server" ID="RadTreeView1" OnClientContextMenuShowing="onContextMenuShowing"
        OnClientContextMenuShown="onContextMenuShown" OnClientContextMenuItemClicked="onContextMenuItemClicked">
        <ContextMenus>
            <telerik:RadTreeViewContextMenu ID="menu1">
                <Items>
                    <telerik:RadMenuItem Text="MoveUp" />
                    <telerik:RadMenuItem Text="MoveDown" />
                    <telerik:RadMenuItem Text="Send E-Mail" />
                </Items>
            </telerik:RadTreeViewContextMenu>
        </ContextMenus>
        <Nodes>
            <telerik:RadTreeNode Text="People">
                <Nodes>
                    <telerik:RadTreeNode Text="Johny" Value="johny@domain.com" />
                    <telerik:RadTreeNode Text="Jimmie" Value="jimmie@domain.com" />
                    <telerik:RadTreeNode Text="Donie" Value="donie@domain.com" />
                </Nodes>
            </telerik:RadTreeNode>
        </Nodes>
    </telerik:RadTreeView>
    And here is the JavaScript:
    function onContextMenuShowing(sender,args) {
        debugger;
        var menu=args.get_menu();
        var node=args.get_node();
        menu.get_items().getItem(2).set_navigateUrl("mailto:"+node.get_value());
    }
     
    function onContextMenuShown(sender,args) {
        var menu=args.get_menu();
        var node=args.get_node();
     
        menu.get_items().getItem(0).set_enabled(true);
        menu.get_items().getItem(1).set_enabled(true);
        menu.get_items().getItem(2).set_enabled(true);
     
        if(node.get_index()==0)
            menu.get_items().getItem(0).set_enabled(false);
        if(node.get_index()==(node.get_parent().get_nodes().get_count()-1))
            menu.get_items().getItem(1).set_enabled(false);
        if(node.get_value()==null)
            menu.get_items().getItem(2).set_enabled(false);
     
     
    }
     
    function onContextMenuItemClicked(sender,args) {
        if(args.get_menuItem().get_text()=="Send E-Mail")
            return;
     
        var root=args.get_node().get_parent();
        var node=args.get_node();
        var nodeIndex=node.get_index();
     
        if(args.get_menuItem().get_text()=="MoveUp") {
            nodeIndex--;
        } else {
            nodeIndex++;
        }
        root.get_nodes().insert(nodeIndex,node);
    }

    I hope this is going to help you!


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Neerav
    Neerav avatar
    50 posts
    Member since:
    Nov 2010

    Posted 18 Dec 2010 Link to this post

    Hello everyone,
    I have a radtreeview on aspx page. It is bind through a xml file and has checkboxes enabled.
    There is another button on the same page. Now what I want is when the use click on button, all the checked nodes should get uncheked.
    Can anyone let me know as to how to go for this.
    ---------------------------------------------------------------------------------------------------

    I have bind the radtreeview using  following method
    this.RadTreeView1.LoadContentFile("test.xml");
    I want to show checkboxes only on parent nodes but not on child nodes.
    Can anyone let me kow as to how to go for this.

    Thanks and Regards



  4. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 21 Dec 2010 Link to this post

    Hello Neerav,

    About unchecking all nodes:
    // button click client-side handler
    function onClientClick()
    {
       var tree = $find("RadTreeView1");
        
       tree.trackChanges();
       tree.uncheckAllNodes();
       tree.commitChanges();
    }

    Well for the nodes that shouldn't be checkable, you only need to set their Checkable property to false.


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
  5. Neerav
    Neerav avatar
    50 posts
    Member since:
    Nov 2010

    Posted 21 Dec 2010 Link to this post

    Hello  Telerik Staff

    We have an issue here.
    PFA the screen shot of our current scenario.

    In "Figure1" we have a tree view "User Hierarchy". This treeview has binded with nodes using serversidecallback load on demand.
     
    Now in "Figure2" there is a "search" option on top of the page. On clicking the magnifying icon the "Search Results" grid gets opened up. Now in the grid you can see there is a "<-" arrow sign which on click will search the corresponding node in "User Hierarchy" and display the node by highlighting it in "User Hierarchy" as displayed in "Figure3" and "Figure4".
     
    "Figure4" is the actual image("Figure3" is for unserstanding purpose about the hierarchy), as it highlights the node to top of the tree("User Hierarchy").
     
    We are trying to implement the same in our demo application.
    Can you suggest us as to how to search such node in "User Hierarchy" and highlighting it in the same at the node to top of the tree("User Hierarchy").
     
    Since our tree is binded by serversidecallback load on demand, using RadTreeView.GetAllNodes() will not work if I search any child node.
    Kindly provide us proper solution to this and let us know if we are not going correct.
     
    Awaiting your reply.
     
    Thanks and Regards
  6. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 23 Dec 2010 Link to this post

    Hello Kevin,

    I have posted an answer in this thread: http://www.telerik.com/community/forums/aspnet-ajax/treeview/adding-context-menus-dynamically-for-childnode-while-using-load-on-demand-webservice-method-for-populating-the-tree-node.aspx


    Regards,
    Nikolay Tsenkov
    the Telerik team
    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Back to Top