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

Different context menus in tree and treenodes

3 Answers 432 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
pixelware
Top achievements
Rank 1
pixelware asked on 17 Mar 2009, 11:38 AM
Hi Telerik Team,

We are having some problems with context menus in a radtreeview. I'll try to explain myself. We want to have two different context menus: one in the tree nodes and another different one in the tree view. That's because we want to have actions performed on a tree node (copy, paste, rename...), and different actions performed on the tree (add new nodes to tree.Nodes).

We don't want to have a root node at tree.Nodes where the rest of nodes hang, so that's what we've done so far:

We have a treeview. With a ContextMenuManager we add a context menu to the treeview ('treeviewContextMenu').
   this.radContextMenuManager1.SetRadContextMenu(this.treeView1,this.radContextMenuTree); 

Programmaticaly we add nodes to the tree, and we add a different contextmenu to the nodes:
RadTreeNode node = new RadTreeNode(); 
// fill more node properties 
node.ContextMenu = radContextMenuNodes.DropDown; 

At first we thought it worked but now we want to use this on a different tree where the nodes context menu has only one option while the tree one has many. And now we realized that both context menu are showing! Nodes context menu above tree context menu.

http://img129.imageshack.us/img129/2296/80110580.jpg

What are we doing wrong? Is there a way to do what we need? Could you help us, please?

We are using Q3 2008 version.

Thanks in advance.

Teba.


3 Answers, 1 is accepted

Sort by
0
Accepted
Victor
Telerik team
answered on 18 Mar 2009, 12:56 PM
Hello pixelware,

Thank you for writing. You should try setting the RadContextMenu property of treeView1 to a RadDropDown menu and the ContextMenu property of RadTreeNode to another RadDropDownMenu. This should work as expected. Here is a code snippet to demonstrate this idea:

public Form1()  
{  
    InitializeComponent();  
    RadDropDownMenu m = new RadDropDownMenu();  
    m.Items.Add(new RadMenuItem("Item1"));  
    m.Items.Add(new RadMenuItem("Item1"));  
    m.Items.Add(new RadMenuItem("Item1"));  
    this.radTreeView1.RadContextMenu = m;  
 
    RadDropDownMenu m2 = new RadDropDownMenu();  
    m2.Items.Add(new RadMenuItem("NodeMenuItem1"));  
    this.radTreeView1.Nodes[0].ContextMenu = m2;  

Please try the above code and let me know if you experience any problems. I am looking forward to your reply.

All the best,
Victor
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.
0
c e
Top achievements
Rank 1
answered on 13 Jan 2011, 03:05 PM

Hi, I'm testing Winform 2010 Q3
I have the same problem with context menu in radTreeView as pixelware.

I have 2 radTreeViews in the same form.

In design time I added an radContextMenuManager with a contextmenu for the control:

radContextMenuManager1.SetRadContextMenu(rtvIncluidos, ContextMenuEntities);

then programatically I added several nodes to the tree view
RadTreeNode newNode = new RadTreeNode();
newNode.Text = "Test node";
newNode.ContextMenu = ContextMenuNode;

The problem is that when I right-click the node, it shows both conext menus, the node context menu on top of the tree view conext menu.

I found a solution (kind of), adding code to DropDownOpening event like this

private void ContextMenuNode_DropDownOpening(object sender, CancelEventArgs e)
{
  if (this.rtvIncluidos.SelectedNode != null)
  {
    ContextMenuEntities.DropDown.ClosePopup(RadPopupCloseReason.CloseCalled);
          .....
          .....

But the problem is that sometimes the tree view context menu shows up and then it close immediatly, and that is an annoying effect.

Which is the right way to do this?

Thanks in advance

Carlos
0
Julian Benkov
Telerik team
answered on 18 Jan 2011, 05:35 PM
Hello Carlos,

You can cancel the opening of the RadTreeView context menu in this scenario. Here is a sample code snippet:

this.radContextMenuManager1.SetRadContextMenu(this.radTreeView2, this.radContextMenu1);
this.radContextMenu1.DropDownOpening += new CancelEventHandler(radContextMenu1_DropDownOpening);
 
RadContextMenu menu1 = new RadContextMenu();
menu1.Items.Add(new RadMenuItem("TestAction"));
this.radTreeView2.Nodes[0].ContextMenu = menu1;
 
void radContextMenu1_DropDownOpening(object sender, CancelEventArgs e)
{
    if (this.radTreeView2.SelectedNode != null && this.radTreeView2.SelectedNode.ContextMenu != null)
    {
        e.Cancel = true;
    }
}

I hope this was helpful.

Kind regards,
Julian Benkov
the Telerik team
Q3’10 SP1 of RadControls for WinForms is available for download; also available is the Q1'11 Roadmap for Telerik Windows Forms controls.
Tags
Treeview
Asked by
pixelware
Top achievements
Rank 1
Answers by
Victor
Telerik team
c e
Top achievements
Rank 1
Julian Benkov
Telerik team
Share this question
or