RadTreeView Right Click working in outside of the nodes(Empty space) also

2 posts, 0 answers
  1. Runjith
    Runjith avatar
    26 posts
    Member since:
    Mar 2014

    Posted 08 Jul 2014 Link to this post

    I am using Telerik RadTreeView control, I have implemented context menu when i right click for selected treenode,if i right click empty space same context menu displaying.How to remove contextmenu for empty place.

  2. Martin Ivanov
    Martin Ivanov avatar
    2297 posts

    Posted 09 Jul 2014 Link to this post

    Hello Ranjith,

    Without your implementation I cannot be sure what is causing the reported behavior behavior. I prepared a sample project that demonstrates how you can implement context menu for each RadTreeViewItem. Basically you can define the context menu for the UI element placed in the ItemTemplate of the RadTreeView.
        <HierarchicalDataTemplate ItemsSource="{Binding Children}">
            <TextBlock Text="{Binding Title}" HorizontalAlignment="Stretch" ContextMenuOpening="TextBlock_ContextMenuOpening">
                                    <TextBlock Text="Context menu item for tree item with Header: "/>
                                    <TextBlock Text="{Binding Title}" />                                                      
                        <MenuItem Header="Item 2" />

    If your context menu is defined for the entire treeview, instead for each item, you can subscribe for the ContextMenuOpening event of the RadTreeView and inside the handler check if the item under the mouse is a RadTreeViewItem, if it's not handle the event. This will prevent displaying the context menu.
    private void RadTreeView_ContextMenuOpening(object sender, ContextMenuEventArgs e)
        var elementUnderMouse = // get item under the mouse cursor position or the RadTreeViewItem which IsMouseOver property is set to True
        if (elementUnderMouse is RadTreeViewItem)
            e.Handled = true;

    Please give the project a try and let me know if it helps. If not, can you please open a new support ticket and send me an isolated project with your implementation. This will help me in better understanding your scenario and assist you further.

    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
Back to Top