How to add submenu items to menuitems

后端 未结 4 973
旧巷少年郎
旧巷少年郎 2021-01-02 09:33

I have created a Table layout in windows forms as shown in figure, i have added a right mouse button click Menu to my table,

i wnt to add submenu items to following

相关标签:
4条回答
  • 2021-01-02 09:56

    You can add This

    var someMenu= new MenuItem("Foo");
    someMenu.MenuItems.Add( new MenuItem("foo "));
    
    0 讨论(0)
  • 2021-01-02 10:08

    That format doesn't work for me. I'm forced to use:

    // People often exclude the applicable "using" statements--so samples don't work!
    using System.Web.UI.WebControls; 
    
    // Create the MAIN menu item
    MenuItem mnuMenuItem = new MenuItem();         
    
    // Create the SUB menu item
    MenuItem mnuSubMenuItem = new MenuItem();      
    
    // Create the SUB menu item, "under" the MAIN menu item!
    mnuMenuItem.ChildItems.Add(mnuSubMenuItem);  
    
    0 讨论(0)
  • 2021-01-02 10:13
    MenuItem newMenuItem1 = new MenuItem("Employee Master");
                MenuItem mnuSubMenuItem = new MenuItem();
                newMenuItem1.ChildItems.Add(mnuSubMenuItem);
                mnuSubMenuItem.Text = "Add User...";
                mnuSubMenuItem.NavigateUrl = "ADDURL.aspx";
    
                MenuItem mnuSubMenuItem1 = new MenuItem();
                newMenuItem1.ChildItems.Add(mnuSubMenuItem1);
                mnuSubMenuItem1.Text = "Edit User...";
                mnuSubMenuItem1.NavigateUrl = "EDITURL.aspx";
                this.MenuMaster.Items.Add(newMenuItem1);
    
    0 讨论(0)
  • 2021-01-02 10:17

    You can add MenuItems to existing MenuItem like:

    MenuItem addDevice = new MenuItem("Add Device");
    addDevice.MenuItems.Add( new MenuItem("Add More .."));
    

    It would be visible like:

    enter image description here

    0 讨论(0)
提交回复
热议问题