Reputation: 105
I have a Contextmenustrip menu. One item has a submneu. When user clicks on a main item of menu, the "ItemClicked" event fires, but Clicking on a submenu items, does not fire the "ItemClicked" event. How can i get the "ItemClicked" event by clicking on submenu items as well as main menu items?
Upvotes: 0
Views: 842
Reputation: 34150
You must write your code in the Click event of the submenuitem itself.
in design time, click on menu to open it, then double click on submenu item to open its click event (or click on it and then in properties window, choose events and find its click event).
If you want to handle all submenuitems click event with one click event. then click on submenu in design time and in event section of its properties, find the click event, use the arrow down before it, and select the exsiting click event.
Or do it programmatically:
foreach(ToolStripMenuItem tmi in this.Controls.OfType<ToolStripMenuItem>())
tmi.Click += (s,ev) => {
// your code here
};
Upvotes: 1
Reputation: 53
The problem is that it is two different controls, each of these has its own event handler. Subscribe your child menu 'ItemClicked' to the same event handler its parent control uses.
i.e:
parent.ItemClicked += itemClicked;
child.ItemClicked += itemClicked;
where itemClicked
is a method where you process ItemClicked
event.
Upvotes: 0