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

ContextMenuOpening for treeview background?

1 Answer 99 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
Kristoffer
Top achievements
Rank 1
Kristoffer asked on 26 Feb 2013, 04:22 PM
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?

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 01 Mar 2013, 02:35 PM
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();
    myMenu.Items.Add(item);
    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.

Greetings,
Stefan
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.
Tags
Treeview
Asked by
Kristoffer
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or