Click Event for RadSplitbutton MenuItem added programmatically

1 Answer 166 Views
Buttons, RadioButton, CheckBox, etc ButtonTextBox TextBox
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
Gone2TheDogs asked on 13 Apr 2022, 10:24 PM

I have a RadSplitButton that I build menuItems programmatically. But, I can't figure out how to capture a click event when the menuItem is clicked. 

The reason I'm doing it this way is because I have a RadbuttonTextbox with the RadSplitButton on its LeftButtonsItems collection.

The RadSplitButton contains previously entered data in the TextBox. The textbox is a Key field for the form, so the radSplitbutton would be perfect for this use if I can get it to work.

 

 

Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
commented on 14 Apr 2022, 09:55 PM | edited

No response. So, I thought I would add a bit more detail on what I've tried but the click event is NOT triggering.

Screenshots and code

User has entered a value in a textfield

User clicks on the cancel button

code to add text from textfield as a new RadSpinbutton MenuItem and create the MenuItem Click Event

User clicks on MenuItem from RadSpinButton

Code : MenuItem Click Event : Text for selected MenuItem is entered into the TextField


		private void cmdCancel_Click(object sender, EventArgs e)
		{
			//if it is okay to cancel current work, 
			AddToPreviousList(txtbutKey.Text);
			CleanUp();
			//focus to key field;
		}

		private void AddToPreviousList(string key)
		{
			if (! string.IsNullOrEmpty(txtbutKey.Text))
			{
				lstPreviousKey.Add(txtbutKey.Text);
			}
		}

		private void CleanUp()
		{
			foreach(string key in lstPreviousKey)
			{
				sbutPrevKey.Items.Add(new RadMenuItem(key, new System.EventHandler(this.MenuItem1_Click)));
				dbutPrevKey.Items.Add(new RadMenuItem(key, new System.EventHandler(this.MenuItem1_Click)));
			}
			EnablePreviousButton(true);
			EnablePanel(ePanel.Key);
		}
		private void MenuItem1_Click(Object sender, System.EventArgs e)
		{
			// Code goes here that handles the Click event.
			string sMenuItem = (sender as RadMenuItem).Text;
			txtbutKey.Text = sMenuItem;
		}

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 18 Apr 2022, 07:41 AM

Hello, Bob,

I have reviewed the provided sample project in the support ticket. It seems that there is a subscription to the Click event only for radMenuItem1. Please have in mind for every newly added menu item, it is necessary to subscribe to this new item's Click event like it is demonstrated below: 

		private void LoadDropdownMenu()
		{
			dbutPrevUsername.Items.Clear();

			foreach (string key in lstPrevUser)
			{
                RadMenuItem item = new RadMenuItem(key);
                item.Click+=item_Click;
		dbutPrevUsername.Items.Add(item);

			}
		}

        private void item_Click(object sender, EventArgs e)
        {
            RadMenuItem item = sender as RadMenuItem;
            Console.WriteLine(item.Text);
        }

I hope this information helps. If you need any further assistance please don't hesitate to contact me. 

Regards,
Dess | Tech Support Engineer, Principal
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Buttons, RadioButton, CheckBox, etc ButtonTextBox TextBox
Asked by
Gone2TheDogs
Top achievements
Rank 1
Iron
Veteran
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or