Hot to catch radcontextmenu item click

4 posts, 0 answers
  1. pogy
    pogy avatar
    17 posts
    Member since:
    Mar 2014

    Posted 30 Mar 2014 Link to this post

    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
  2. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 02 Apr 2014 Link to this post

    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.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Rawad
    Rawad avatar
    23 posts
    Member since:
    Jan 2012

    Posted 09 Jul 2014 Link to this post

    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 
  5. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 11 Jul 2014 Link to this post

    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.
     
Back to Top