How to add submenu items to menuitems

hs.chandra picture hs.chandra · Apr 22, 2013 · Viewed 41.3k times · Source

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 menuitems such as

When i click add device it should show subitems such as sounder, MCP, strobe etc When i click fault it should show subitems such as open circuit fault, sounder fault, `short circuit fault' so on

This is how i created menuitems

    ContextMenu m = new ContextMenu();
    MenuItem addDevice = new MenuItem("Add Device");
    MenuItem deleteDevice = new MenuItem("delete Device");
    MenuItem fire = new MenuItem("Fire");
    MenuItem fault = new MenuItem("Fault");
    MenuItem suppress = new MenuItem("Suppress");
    m.MenuItems.AddRange(new MenuItem[] { addDevice, deleteDevice, fire, fault,suppress});
    tableLayout.ContextMenu = m;
    m.Show((Control)(sender), e.Location);

The below is my form and table layout

http://i48.tinypic.com/33ok3cw.jpg

Answer

Habib picture Habib · Apr 22, 2013

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