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

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

4 Answers 433 Views
ContextMenu
This is a migrated thread and some comments may be shown as answers.
Andrea
Top achievements
Rank 1
Andrea asked on 17 Jan 2019, 09:36 AM

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;
        }

 

 

 

4 Answers, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 18 Jan 2019, 01:24 PM
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.
0
Andrea
Top achievements
Rank 1
answered on 18 Jan 2019, 01:34 PM

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

 

0
Accepted
Dimitar
Telerik team
answered on 21 Jan 2019, 12:34 PM
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.
0
Andrea
Top achievements
Rank 1
answered on 21 Jan 2019, 01:37 PM

Hi Dimitar, thank you, that works fine.

Andrea

Tags
ContextMenu
Asked by
Andrea
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Andrea
Top achievements
Rank 1
Share this question
or