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

Hot to catch radcontextmenu item click

3 Answers 913 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
pogy
Top achievements
Rank 1
pogy asked on 30 Mar 2014, 10:28 AM
Hello,

I can't find the event when i click on a radContextMenu.
I added few items and from my radListControl after right click on radListControl item and choose my radContextMenu item i want to catch my click event.
i only can see that radContextMenu has different events like DropDownClosed, DropDownClosing, DropDownOpened and DropDownOpenning

3 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 02 Apr 2014, 09:17 AM
Hi Pogy,

Thank you for writing.

The RadContextMenu itself does not have Click event. Generally, you should subscribe to its items Click events. For example, you can initialize the context menu like this:
RadContextMenu contextMenu;
  
public Form1()
{
    InitializeComponent();
  
    contextMenu = new RadContextMenu();
    RadMenuItem menuItem1 = new RadMenuItem("Item 1");
    menuItem1.ForeColor = Color.Red;
    menuItem1.Click += menuItem1_Click;
   contextMenu.Items.Add(menuItem1);
}
  
void menuItem1_Click(object sender, EventArgs e)
{
    RadMessageBox.Show("Menu item 1 clicked");
}

More information about this can be found in the following article: RadMenuItem Events.
 
Let me know if you have additional questions.
 
Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rawad
Top achievements
Rank 2
answered on 09 Jul 2014, 06:31 AM
Hello Dimitar

Hope you are good.
I have 2 questions:

1- I'm trying to catch events of item in contextmenu, but in your solution, we must add the radcontextmenu by code,  but if we add it by design, how to catch events of the item.

2- how to disable or enable items inside contextmenu, when we attach the contextmenu to the treeview. for example in my contextmenu i have the following items.     1- New    2- Edit    3- Delete,    When the user Right Click on a node1  I want to disable  2- Edit , 3- Delete,   but when the user Right click on node2 ,  I want to enable them and disable 1-New ,   etc . . .

Thanks 
0
Dimitar
Telerik team
answered on 11 Jul 2014, 03:04 PM
Hi Rawad,

Thank you for writing.

1. It does not matter how you have added the items. You can subscribe to their event the same way in both cases. When you are adding items design time the code for them is automatically added for you. However you can still access them as usual. For example if you add some items your designer generated code will look like the attached image. Then you can subscribe to the Click event as usual:
public Form1()
{
    InitializeComponent();
    radMenuItem1.Click += radMenuItem1_Click;
}
 
void radMenuItem1_Click(object sender, EventArgs e)
{
     
}

2. You can enable or disable the any item by setting its Enabled property to before showing the menu:
radMenuItem1.Enabled = false;

I hope this helps. Should you have any other questions do not hesitate to ask.
 
Regards,
Dimitar
Telerik
 
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.
 
Tags
ContextMenu
Asked by
pogy
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Rawad
Top achievements
Rank 2
Share this question
or