multiselect nodes context menu postback issue

4 posts, 0 answers
  1. cramer
    cramer avatar
    6 posts
    Member since:
    Jul 2011

    Posted 27 Jun 2013 Link to this post

    Hello,

    Have a treeview and multiple nodes selected.

    On server side click of context menu can not get the treeview selected nodes as always returns a count of 0.
    How can I get the selected nodes to apply the context menu command to each?

    Example: 
    select 3 nodes and context menu command "Copy"
    on server side can only ever access the node via RadTreeViewContextMenuEventArgs node

    Need to be able to loop and do the "Copy" command on the 3 selected nodes...

    Thanks,

    Marc Cramer
  2. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 02 Jul 2013 Link to this post

    Hello,

    Indeed in the RadTreeViewContextMenuEventArgs object you are able to access only the right clicked node. In order to access the checked nodes I would suggest using the RadTreeView object property CheckedNodes and this will return a collection with all checked nodes. Since this is a collection you can iterate through its items and get the information you need for each item.  Here is a sample code that implements very similar scenario:
    //markup code

    <telerik:RadTreeView ID="RadTreeView1" runat="server" CheckBoxes="true" OnContextMenuItemClick="RadTreeView1_ContextMenuItemClick">
        <Nodes>
            ....
        </Nodes>
        <ContextMenus>
            <telerik:RadTreeViewContextMenu>
                <Items>
                    <telerik:RadMenuItem Text="Item 1"></telerik:RadMenuItem>
                    <telerik:RadMenuItem Text="Item 2"></telerik:RadMenuItem>
                </Items>
            </telerik:RadTreeViewContextMenu>
        </ContextMenus>
    </telerik:RadTreeView>
    //code behind
    protected void RadTreeView1_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)
        {
            Label1.Text = "Checked nodes count: " + RadTreeView1.CheckedNodes.Count;
        }


    Regards,
    Boyan Dimitrov
    Telerik
    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 the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. cramer
    cramer avatar
    6 posts
    Member since:
    Jul 2011

    Posted 02 Jul 2013 Link to this post

    Replied to the ticket request...
    Thanks.
  5. cramer
    cramer avatar
    6 posts
    Member since:
    Jul 2011

    Posted 02 Jul 2013 Link to this post

    appears that the naming convention for events was misleading me...

    Was under impression order of events would be
    • onClientContextMenuItemClicking
    • RadTreeView1_ContextMenuItemClick
    • onClientContextMenuItemClicked

    The order they are actually occurring for me is

    • onClientContextMenuItemClicking
    • onClientContextMenuItemClicked
    • RadTreeView1_ContextMenuItemClick

    so under my assumption I was deselecting all nodes at the onClientContextMenuItemClicked event since I assumed we had all ready handled the RadTreeView1_ContextMenuItemClick event.

    Thanks.

Back to Top