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

RadContextMenu not painting properly

1 Answer 77 Views
Treeview
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 22 Jun 2012, 04:08 PM
Morning,
Before I log this as an issues, I want to ensure that what I am doing is correct.  I am using the RadTreeView with 3 levels of node and I am dynmaic assigning context menus based on the level.

private void RadTreeView1_SelectedNodeChanged(object sender, RadTreeViewEventArgs e)
{
    if (e.Node.Level == 0) 
         { 
                 e.Node.ContextMenu =ContextMenu1 ; 
         } 
     else if (e.Node.Level == 1) 
        { 
                 e.Node.ContextMenu =ContextMenu2; 
        } 
     else (e.Node.Level == 2) 
        { 
                e.Node.ContextMenu =ContextMenu3 ; 
        } 
}

When I right click on the level 2, my context menu works perfect.  When I right click on any other level, I get a single line of pixels which I believe is my menu.  Am I doing the correctly?

Thanks

James

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 26 Jun 2012, 02:56 PM
Hello James,

We have addressed the question in the support ticket that you have opened about the same topic. I am pasting the answer here in case there are other people interested in the answer:

This line of pixels would happen if your context menu is empty. Could you please make sure that you are filling the menu with items? 

Instead of the approach that you are currently following, I would recommend handling the ContextMenuOpening event where you can have greater control over the behavior of the context menus. The Node property of the event arguments will return the node for which the context menu is clicked, so you again will be able to achieve your scenario. 

Please note that in order to make the ContextMenuOpening event fire, you need to set the AllowDefaultContext menu to true:

this.radTreeView1.AllowDefaultContextMenu = true;

And this could be the ContextMenuOpening implementation: 
void radTreeView1_ContextMenuOpening(object sender, TreeViewContextMenuOpeningEventArgs e)
{
    if (e.Node.Level == 1)
    {
        e.Menu.Items.Clear();
        e.Menu.Items.Add(new RadMenuItem("My Menu Item"));
    }
}

A bit off topic, I would kindly ask you to avoid double posting one and the same question as this may slow down our response and may lead to confustion. In case you require a quick answer according to your license, please directly open a new support ticket. Thank you for your understanding. Greetings,
Svett
the Telerik team
RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
Tags
Treeview
Asked by
James
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or