.net - Generating a second context menu dynamically in Winforms -


I have a context menu with some selection, if the user chooses a particular option, then I have options in a second menu Want a list These options come from a data store and will be unique to that user.

I see how in the designer you can add a set of options that show the user when making a selection. However, when you do not need to come out of the data and design it in the designer, what do you do?

To create a cascading menu in a way: in your context menu, the "parent" Add an item to work in the form and add a hair menu item to the parent's item. After that attach an event handler to the events of the parent item, and add something like this to:

  Private Zero ParentMenuItem_DropDownOpening (Object Sender, EventArgs e) {IEnumerable & lt; String & gt; Item = find (); _parentMenuItem.DropDownItems.Clear (); Foreign items (items in a variety of items) {_parentMenuItem.DropDownItems.Add (item); }}  

Every time it is opened, the child will populate the menu (add caching as needed)

Technically, add this dummy hair item , But by adding a child, the parent menu arrow will show that it is a cascading hair menu.


Comments