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

multiselect nodes context menu postback issue

3 Answers 76 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
cramer
Top achievements
Rank 1
cramer asked on 27 Jun 2013, 10:53 PM
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

3 Answers, 1 is accepted

Sort by
0
Boyan Dimitrov
Telerik team
answered on 02 Jul 2013, 10:21 AM
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.
0
cramer
Top achievements
Rank 1
answered on 02 Jul 2013, 04:36 PM
Replied to the ticket request...
Thanks.
0
cramer
Top achievements
Rank 1
answered on 02 Jul 2013, 06:01 PM
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.

Tags
TreeView
Asked by
cramer
Top achievements
Rank 1
Answers by
Boyan Dimitrov
Telerik team
cramer
Top achievements
Rank 1
Share this question
or