Programmatically add Sub Menus to a ContextMenuStrip

  • Thread starter Thread starter JB
  • Start date Start date
J

JB

Hi All,

I've always so far designed menus at design time and never had a
problem.
Today I want to create menus programmatically and add Sub Menus to a
ContextMenuStrip.
How can I programmatically reproduce what I do at design time by
setting the DropDown property of a Menu Item to the Sub Menu I wat to
attach to it?

The DropDown property doesn't exist on a ToolStripItem and I've tried
to play with the Owner property without any luck.

Any help or pointer would be greatly appreciated.
Thanks
JB
 
JB said:
I've always so far designed menus at design time and never had a
problem.
Today I want to create menus programmatically and add Sub Menus to a
ContextMenuStrip.
How can I programmatically reproduce what I do at design time by
setting the DropDown property of a Menu Item to the Sub Menu I wat to
attach to it?

The DropDown property doesn't exist on a ToolStripItem and I've tried
to play with the Owner property without any luck.

Just check the button on top of the solution explorer to show hidden files.
Then navigate to the "<form name>.Designer.vb" file of a form on which you
already added the toolstrip. It will contain the source code generated by
the designer to set up the menu. This should give you an idea on how to
create the menus.
 
Just check the button on top of the solution explorer to show hidden files.
Then navigate to the "<form name>.Designer.vb" file of a form on which you
already added the toolstrip.  It will contain the source code generatedby
the designer to set up the menu.  This should give you an idea on how to
create the menus.

Thanks very much for that tip Herfried. I found the trick. The
designer uses a ToolStripMenuItem class and not a ToolStripItem as
returned by the ToolStripItemCollection.Add function.
 
Back
Top