Different context menus in tree and treenodes

4 posts, 1 answers
  1. pixelware
    pixelware avatar
    2 posts
    Member since:
    Nov 2006

    Posted 17 Mar 2009 Link to this post

    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').
    1    this.radContextMenuManager1.SetRadContextMenu(this.treeView1,this.radContextMenuTree); 

    Programmaticaly we add nodes to the tree, and we add a different contextmenu to the nodes:
    1 RadTreeNode node = new RadTreeNode(); 
    2 // fill more node properties 
    3 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.


  2. Answer
    Victor
    Admin
    Victor avatar
    1351 posts

    Posted 18 Mar 2009 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. c e
    c e avatar
    5 posts
    Member since:
    Apr 2010

    Posted 13 Jan 2011 Link to this post

    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
  5. Julian Benkov
    Admin
    Julian Benkov avatar
    1135 posts

    Posted 18 Jan 2011 Link to this post

    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.
Back to Top