Rad Context Menu on more than one control

8 posts, 1 answers
  1. Jalal Eddin
    Jalal Eddin avatar
    1 posts
    Member since:
    Jul 2010

    Posted 08 Sep 2010 Link to this post

    Dear All,

    I'm facing a problem in using RadContextMenu, my form contains three charts and i want to assign the same menu for all of them so i used The RadContextMenu property to assign the menu, but my problem is when the user pick any choice from the menu, how can i know on which chart did the user click ?? the sender contains rad menu control not the chart control.

    Thank you
  2. Answer
    Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 13 Sep 2010 Link to this post

    Hi Jalal Eddin,

    Thank you for writing.

    Currently, in order to determine which control has been clicked, you should track down the element that is under the mouse when the context menu is opened. Please consider the following code snippet that demonstrates this behavior:
    public Form1()
    {
        InitializeComponent();
        radContextMenu1.DropDownOpened += new EventHandler(radContextMenu1_DropDownOpened);
    }
     
    Point p;
    Control currentControl;
     
    void radContextMenu1_DropDownOpened(object sender, EventArgs e)
    {
        p = ((RadContextMenu)sender).DropDown.Location;
        TraverseControls(this);
    }
     
    public void TraverseControls(Control ctrl)
    {
        foreach (Control control in ctrl.Controls)
        {
            if (control == ctrl.GetChildAtPoint(ctrl.PointToClient(p)) && control.Controls.Count > 0)
            {
                currentControl = control;
                TraverseControls(control);
            }
            else if (control == ctrl.GetChildAtPoint(ctrl.PointToClient(p)))
            {
                currentControl = control;
            }
        }
    }

    I will add this case as a feature request in our issue tracking system and we will consider implementing a more intuitive behavior in a future release.

    I have updated your Telerik points for this request. If there is anything else I can assist you with, do not hesitate to contact me.


    Sincerely yours,
    Stefan
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Joy
    Joy avatar
    7 posts
    Member since:
    Sep 2014

    Posted 03 Dec 2014 in reply to Stefan Link to this post

    All,

    I'm currently facing a similar need as Jalal from the original post 4 years ago. I'm currently needing to determine the appropriate CheckedListBox the mouseDown event originated from.

    Has this request been implemented yet or do I need to try the suggested code below?

    Thanks!
  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 04 Dec 2014 Link to this post

    Hello Joy,

    This is not implemented in the suite, however, I can offer an even easier solution to access the caller control with a single line of code:
    void radContextMenu1_DropDownOpening(object sender, CancelEventArgs e)
    {     
        Control parent = this.GetChildAtPoint( this.PointToClient( Control.MousePosition));
    }

    If we receive more requests to include the control in the event information, we will consider it in a future release.

    Regards,
    Stefan
    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.

     
  6. Joy
    Joy avatar
    7 posts
    Member since:
    Sep 2014

    Posted 04 Dec 2014 in reply to Stefan Link to this post

    Stefan –

    The provided line of code did not work for me. The parent Control variable is picking up the RadGroupBox instead of the CheckedListBox. I’m not sure if it’s because I dynamically created the CheckedListBox or it’s just an issue with layered controls. Please see my sequences of layered controls from Bottom to Top.

    RadGroupBox > Panel > CheckedListBox

    Thank You.
  7. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 05 Dec 2014 Link to this post

    Hello Joy,

    That is correct, this method will return just the first level control. The following thread notes how you can get the topmost one: http://stackoverflow.com/questions/7508943/getchildatpoint-method-is-returning-the-wrong-control.

    I hope this helps.

    Regards,
    Stefan
    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.

     
  8. Joy
    Joy avatar
    7 posts
    Member since:
    Sep 2014

    Posted 05 Dec 2014 in reply to Stefan Link to this post

    Thanks Stefan for the help! 

    In theory this should work, but in my case it gets to the Panel level and then returns null. It doesn't see the CheckedListBox for some reason. May be because it dramatically created. I'll just stick with the original solution for now.

    Thanks again.
  9. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 08 Dec 2014 Link to this post

    Hi Joy,

    Thank you for writing back.

    I have logged a feature request in our feedback portal. Please refer to the following feedback item. For the time being you should continue to use the first workaround proposed in this thread.

    Your Telerik Points have been updated for this request.

    If you have any additional questions, please let me know.

    Regards,
    Peter
    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.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready