ContextMenuOpening for treeview background?

2 posts, 0 answers
  1. Kristoffer
    Kristoffer avatar
    158 posts
    Member since:
    Dec 2012

    Posted 26 Feb 2013 Link to this post

    I can easily show a custom menu when right-clicking tree nodes:

    this.radTreeView.ContextMenuOpening += new Telerik.WinControls.UI.TreeViewContextMenuOpeningEventHandler(this.radTreeView_ContextMenuOpening);

    But this does not trigger when I right-click the treeview background. How can I show a context menu when right-clicking in the white background area?
  2. Stefan
    Stefan avatar
    2908 posts

    Posted 01 Mar 2013 Link to this post

    Hello Kristoffer,

    Thank you for writing.

    The context menu of RadTreeView is designed to be opened only when a node is right clicked since the context of the menu items are relevant to the clicked node. 

    If you want you can show you own context menu when the element is clicked:
        RadContextMenu myMenu = new RadContextMenu();
        RadMenuItem item = new RadMenuItem();
        item.Text = "My item";
        item.Click += item_Click;
    void radTreeView1_MouseDown(object sender, MouseEventArgs e)
        if (e.Button == System.Windows.Forms.MouseButtons.Right)
            RadTreeViewElement el = radTreeView1.ElementTree.GetElementAtPoint(e.Location) as RadTreeViewElement;
            if (el != null)
             myMenu.Show(this.PointToScreen( e.Location)); 

     I hope that you find this information useful.

    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Join us for a FREE webinar to see all the new stuff in action.

    Interested, but can’t attend? Register anyway and we’ll send you the recording.
Back to Top