how to get a reference to the calling control in ContextMenuOpening event

5 posts, 1 answers
  1. Andrea
    Andrea avatar
    73 posts
    Member since:
    Oct 2012

    Posted 17 Jan Link to this post

    Hi, this should be an easy one, how can I fix that?

     

    private void ContextMenuOpening(object sender, TreeBoxContextMenuOpeningEventArgs e)
            {
                //The below line doesn't work:
                //I need to reach the control to provide the contextmenu some "context"
                string myContext = (sender as Control).Name;
     
                cmMarkNullMenuItem.Tag = cmResetMenuItem.Tag = myContext;
                cmResetMenuItem.Enabled = EditorModel.PropertiesByName[myContext].IsChanged;
            }

     

     

     

  2. Dimitar
    Admin
    Dimitar avatar
    2677 posts

    Posted 18 Jan Link to this post

    Hi Andrea,

    You can check the sender by putting a breakpoint in Visual Studio. The attached image shows the code for getting the control name as well.

    Should you have any other questions do not hesitate to ask.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Andrea
    Andrea avatar
    73 posts
    Member since:
    Oct 2012

    Posted 18 Jan in reply to Dimitar Link to this post

    Hi Dimitar, thank you for replying.

    Yes I know which is the sender, the sender is of type RadTextBoxControlElement, my problem is how can I find its control, whose name interests me because it is the key of an autogenerated dynamic property (the radtextboxes too are dynamically generated).

    I tried some options using intellisense but did not find anything good.

    At the moment i'm quite happy with the form's ActiveControl property but maybe it is possible to extract the control from the RadTextBoxElement.

     

    Best

    Andrea

     

  4. Answer
    Dimitar
    Admin
    Dimitar avatar
    2677 posts

    Posted 21 Jan Link to this post

    Hello Andrea,

    Yes, there is a way to get the control and its name. The following can be used for any Telerik WinForms control:
    private void RadTextBoxControl1_ContextMenuOpening(object sender, Telerik.WinControls.UI.TreeBoxContextMenuOpeningEventArgs e)
    {
        var element = sender as RadTextBoxControlElement;
        var controlName = element.ElementTree.Control.Name;
    }

    Your solution to use the active control is good as well.

    Let me know if you have additional questions.

    Regards,
    Dimitar
    Progress Telerik
    Get quickly onboard and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Andrea
    Andrea avatar
    73 posts
    Member since:
    Oct 2012

    Posted 21 Jan in reply to Dimitar Link to this post

    Hi Dimitar, thank you, that works fine.

    Andrea

Back to Top