I have several RadTextBox controls on a form and want to use a single RadContextMenu to provide my own context menu. Depening on which control is selected the resulting action will be a little different.
I have this code to assign my context menus to the 2 controls.
this.txtBreedersAccount.TextBoxElement.TextBoxItem.HostedControl.ContextMenu = new ContextMenu(); this.txtBreedersAccount.TextBoxElement.TextBoxItem.HostedControl.MouseDown += new MouseEventHandler(this.AccountContextMenu_MouseDown); this.txtMemberAccount.TextBoxElement.TextBoxItem.HostedControl.ContextMenu = new ContextMenu(); this.txtMemberAccount.TextBoxElement.TextBoxItem.HostedControl.MouseClick += new MouseEventHandler(this.AccountContextMenu_MouseDown);
This is my MouseDown procedure.
private void AccountContextMenu_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { this.cmnuAccount.Show(MousePosition); } }
All of this works perfectly. My issue is the I can't seem to find a way to determine which of my 2 controls was actually used to instantiate the RadContextMenu. Searching the closest I could get was something like this, but it doesn't work.
private void cmnuAccount_DropDownOpening(object sender, System.ComponentModel.CancelEventArgs e) { RadElement element = sender as RadElement; if (element == null) { return; } this._currentControl = element.ElementTree.Control as RadControl; }
Textboxes seem to be treated differently than other RadControls. If I setup the context menu on a checkbox for example it work without any issues.
I'd appreciate any help that anyone could give. Thanks.