RadMenuItem Events
Usually you will handle the events of the objects that make up a menu, not the RadMenu itself.
RadMenuItem Events
The key event for the RadMenuItem object is the Click event, which is fired when the user selects the menu item or presses the associated shortcut key. If the menu item is designed to display check marks, then the ToggleStateChanging and ToggleStateChanged events fire when a check mark is applied to or removed from the RadMenuItem object.
- ToggleStateChanging: Passes a StateChangingEventArgs parameter with properties for NewValue, OldValue and Cancel. Both NewValue and OldValue are ToggleState enumeration types with values Indeterminate, On and Off. If the Cancel argument is set to true the check-box does not change its state and the ToggleStatedChanged event does not fire.
Handling the ToggleStateChanging event
void radMenuItem2_ToggleStateChanging(object sender, StateChangingEventArgs args)
{
if (args.NewValue == Telerik.WinControls.Enumerations.ToggleState.Indeterminate)
{
args.Cancel = true;
}
}
- ToggleStateChanged: This event fires when the check-box state changes between one of the ToggleState enumeration values of On, Off or Indeterminate. The StateChangedEventaArgs passed to this event handler contain the ToggleState property.
Handling the ToggleStateChanged event
void radMenuItem2_ToggleStateChanged(object sender, StateChangedEventArgs args)
{
MessageBox.Show(args.ToggleState.ToString());
}
RadMenuComboItem Events
For the RadMenuComboItem, you will probably want to work with the events of the embedded ComboBoxElement property. The example below uses the ComboBoxElement.SelectedIndexChanged event to get the currently selected combo box value.
Handling the SelectedIndexChanged event of RadMenuComboItem
void Form1_Load(object sender, EventArgs e)
{
radMenuComboItem1.ComboBoxElement.SelectedIndexChanged += new Telerik.WinControls.UI.Data.PositionChangedEventHandler(ComboBoxElement_SelectedIndexChanged);
}
void ComboBoxElement_SelectedIndexChanged(object sender, EventArgs e)
{
RadListDataItem item = (sender as RadDropDownListElement).SelectedItem as RadListDataItem;
MessageBox.Show(item.Text);
}
RadMenuContentItem
Handle the events for the control assigned to RadMenuContentItem.ContentElement, not the content item itself. In the example below an event handler is attached to the Click event of a button.
Handling events for controls embedded in RadMenuContentItem
RadMenuContentItem buttonItem = new RadMenuContentItem();
RadButtonElement button = new RadButtonElement();
button.Text = "OK";
button.Click += new EventHandler(button_Click);
buttonItem.ContentElement = button;
radMenu1.Items.Add(buttonItem);