Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Dynamically generate submenu items

Dynamically generate submenu items

Dynamically generate submenu items


I am working on a program that will allow a user to set up scenarios for different companies. The basic company data (Name, ID #) are stored in a DB table.

I have a menu item under the File menu that says "Select Company", and I'd like to create submenu entries for each of the companies in the table under that. When they select one, I'll store the Company ID and use it to differentiate the query data for the company selected.

I can easily get the data into a DataTable object as I'm loading up the main form, but I'm not sure how to use it to build the submenu items. Anyone have an example I can follow?

Oh and in case it matters I'm using VB.NET 2008.


RE: Dynamically generate submenu items

CODE --> vb

Dim mi As ToolStripMenuItem = New ToolStripMenuItem(ServicesName)
AddHandler mi.Click, AddressOf ServicesTypeToolStripMenuItem_Click

The above is a snippet from a Services Management program that I have written.

Line 1 creates a new TolStripMenuItem (mi) and gives it a Caption (ServicesName) (Which is a string passed in to this procedure)
*****Line 2 sets up an OnClick handler for the menu item
Line 3 adds this menu item to the DropDownItems list of the appropriate parent menu.

*****The easiest way to do this is to create an OnClick handler for an existing menu item, change all the specific names and remove the Handles Clause. This will leave you with a generic handler for a menu item. In my code there is no menu item "ServicesTypeToolStripMenuItem", however its name is descriptive and it has all the correct parameters.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close