none
Add items to menu at run time RRS feed

  • Question

  • Hi i have a txt file that is seperated by semi colons. I can parse it but i need to add each one to a menu list (menu list control).

    How would i go about doing it

     

    Thx

     

    NOTE: i can do menustrip.items.add ("Item"), but that adds to top item not a sub menu

    Sunday, May 21, 2006 10:28 AM

Answers

  • Lets say your menustrip is menuStrip1 then you would say-

    this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {

    this.fileToolStripMenuItem});//Top level menutoolstripItem which is called "File"

    this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {

    this.editToolStripMenuItem});//Below "File",add sub-item such as "Edit"

    The idea is to add as many ToolStripItems to menustrip or adding more ToolStripItems to already added ToolStripItems to a menu.

    Sunday, May 21, 2006 12:57 PM

All replies

  • Lets say your menustrip is menuStrip1 then you would say-

    this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {

    this.fileToolStripMenuItem});//Top level menutoolstripItem which is called "File"

    this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {

    this.editToolStripMenuItem});//Below "File",add sub-item such as "Edit"

    The idea is to add as many ToolStripItems to menustrip or adding more ToolStripItems to already added ToolStripItems to a menu.

    Sunday, May 21, 2006 12:57 PM
  • yea i got it working thx but i have another problem...

    It loads paths from a file so the menu has

    C:\MyProg.exe

    C:\MyOtherProg.exe

    how do i make it when i click on one it loads the program i have got

     

    Private Sub ApplicationsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ApplicationsToolStripMenuItem.Click

    LoadProgram((Application.StartupPath + "\Programs\" + Me.ApplicationsToolStripMenuItem.DropDownItems.Item(0).ToString)

    End Sub

     

    but that just loads the item(0) of the menu. I need to to be whatever the user clicks on in the dropdown menu... so would i use ApplicationsToolStripMenuItem_Click??

    Sunday, May 21, 2006 6:28 PM