Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. MenuStrip control searching by menue name

MenuStrip control searching by menue name

Scheduled Pinned Locked Moved Visual Basic
questionalgorithmsdata-structurescryptographytutorial
9 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Georg Kohler
    wrote on last edited by
    #1

    This should be an easy one .. But I've been struggling all night over this ... - I'm adding menu items during runtime (keeping track of open files) - I can add the handler for the menu click event - that works .. Question: - How can I search / locate for the "newly" added menuitem just by its Menue NAME [untitled(1)] as an example - Is the best approach the use of a hash table ? (indexed by menu location ?) (I haven't tried this yet) - You would think there is an easy way of searching for the menu name direct ??? Here is how I'm adding the neue menu Item:

    MenuName = "untitled(1)" ' Assigne window name

    WindowsToolStripMenuItem.DropDownItems.Add(MenuName) ' add new created window to menue

    Any ideas Thanks georg

    T S 2 Replies Last reply
    0
    • G Georg Kohler

      This should be an easy one .. But I've been struggling all night over this ... - I'm adding menu items during runtime (keeping track of open files) - I can add the handler for the menu click event - that works .. Question: - How can I search / locate for the "newly" added menuitem just by its Menue NAME [untitled(1)] as an example - Is the best approach the use of a hash table ? (indexed by menu location ?) (I haven't tried this yet) - You would think there is an easy way of searching for the menu name direct ??? Here is how I'm adding the neue menu Item:

      MenuName = "untitled(1)" ' Assigne window name

      WindowsToolStripMenuItem.DropDownItems.Add(MenuName) ' add new created window to menue

      Any ideas Thanks georg

      T Offline
      T Offline
      Thomas Stockwell
      wrote on last edited by
      #2

      The best solution would be to name every menu item both uniquely and meaningful. Then iterate through each menu in the menu system for the particular name.

      Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios Discounted or Free Software for Students: DreamSpark - downloads.channel8.msdn.com MSDN Academic Alliance - www.msdnaa.com

      G 1 Reply Last reply
      0
      • T Thomas Stockwell

        The best solution would be to name every menu item both uniquely and meaningful. Then iterate through each menu in the menu system for the particular name.

        Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios Discounted or Free Software for Students: DreamSpark - downloads.channel8.msdn.com MSDN Academic Alliance - www.msdnaa.com

        G Offline
        G Offline
        Georg Kohler
        wrote on last edited by
        #3

        Thats what I'm trying to do - but I can not figure out what "function" actually lets you find an existing menu name based on a string Any idea how to actually do it ? Indexof / find/ index/ compare and so on have not worked for me (I might not call the correct menu tree as an example:

        WindowName = "untitled(1)"

        test = WindowsToolStripMenuItem.DropDownItems.Find(WindowName, True)

        does not work ???? Where [WindowsToolStripMenuItem] is the actual menu that contains the menuitems I most be doing something wrong :confused: Georg

        T 1 Reply Last reply
        0
        • G Georg Kohler

          Thats what I'm trying to do - but I can not figure out what "function" actually lets you find an existing menu name based on a string Any idea how to actually do it ? Indexof / find/ index/ compare and so on have not worked for me (I might not call the correct menu tree as an example:

          WindowName = "untitled(1)"

          test = WindowsToolStripMenuItem.DropDownItems.Find(WindowName, True)

          does not work ???? Where [WindowsToolStripMenuItem] is the actual menu that contains the menuitems I most be doing something wrong :confused: Georg

          T Offline
          T Offline
          Thomas Stockwell
          wrote on last edited by
          #4

          FYI, if the function doesn't already exist then create the function pseudocode: foreach menuitem in windowstoolstripmenuitem.dropdownitems { if(menuitem.name=='search criteria' OR menuitem.name.contains('search criteria') return correct; else return incorrect; }

          Regards, Thomas Stockwell Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Visit my homepage Oracle Studios Discounted or Free Software for Students: DreamSpark - downloads.channel8.msdn.com MSDN Academic Alliance - www.msdnaa.com

          1 Reply Last reply
          0
          • G Georg Kohler

            This should be an easy one .. But I've been struggling all night over this ... - I'm adding menu items during runtime (keeping track of open files) - I can add the handler for the menu click event - that works .. Question: - How can I search / locate for the "newly" added menuitem just by its Menue NAME [untitled(1)] as an example - Is the best approach the use of a hash table ? (indexed by menu location ?) (I haven't tried this yet) - You would think there is an easy way of searching for the menu name direct ??? Here is how I'm adding the neue menu Item:

            MenuName = "untitled(1)" ' Assigne window name

            WindowsToolStripMenuItem.DropDownItems.Add(MenuName) ' add new created window to menue

            Any ideas Thanks georg

            S Offline
            S Offline
            Scott Dorman
            wrote on last edited by
            #5

            You need to make sure you're actually setting the "Name" property and not the "Text" property. They are different and independent of one another and typically when you create a new menu item you are setting the "Text" property.

            Scott Dorman

            Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


            Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

            G 1 Reply Last reply
            0
            • S Scott Dorman

              You need to make sure you're actually setting the "Name" property and not the "Text" property. They are different and independent of one another and typically when you create a new menu item you are setting the "Text" property.

              Scott Dorman

              Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


              Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

              G Offline
              G Offline
              Georg Kohler
              wrote on last edited by
              #6

              Good point - but I believe I did try this also last night as I changed the search String from "untitled(1)" to "untitled(1)ToolStripMenuItem" = added [ToolStripMenuItem] to the text property the same way as VB 2008 is doing it when you create a menuitem ... But I'll check again tonight :-) Georg

              S 1 Reply Last reply
              0
              • G Georg Kohler

                Good point - but I believe I did try this also last night as I changed the search String from "untitled(1)" to "untitled(1)ToolStripMenuItem" = added [ToolStripMenuItem] to the text property the same way as VB 2008 is doing it when you create a menuitem ... But I'll check again tonight :-) Georg

                S Offline
                S Offline
                Scott Dorman
                wrote on last edited by
                #7

                I just verified on MSDN[^], the call you are making

                WindowsToolStripMenuItem.DropDownItems.Add(MenuName) ' add new created window to menue

                will add a new ToolStripMenuItem whose text is the value of the string MenuName. You have two choices: 1. The Add method returns the actual ToolStripItem that was just added, so you can take that instance and assign a value to the Name property. To do this it would be something like this:

                ToolStripItem item = WindowsToolStripMenuItem.DropDownItems.Add(MenuName)
                item.Name = MenuName

                2. Create the ToolStripItem first and then add it to the collection:

                ToolStripItem item = new ToolStripItem(MenuName)
                item.Name = MenuName
                WindowsToolStripMenuItem.DropDownItems.Add(item)

                Scott Dorman

                Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


                Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

                G 1 Reply Last reply
                0
                • S Scott Dorman

                  I just verified on MSDN[^], the call you are making

                  WindowsToolStripMenuItem.DropDownItems.Add(MenuName) ' add new created window to menue

                  will add a new ToolStripMenuItem whose text is the value of the string MenuName. You have two choices: 1. The Add method returns the actual ToolStripItem that was just added, so you can take that instance and assign a value to the Name property. To do this it would be something like this:

                  ToolStripItem item = WindowsToolStripMenuItem.DropDownItems.Add(MenuName)
                  item.Name = MenuName

                  2. Create the ToolStripItem first and then add it to the collection:

                  ToolStripItem item = new ToolStripItem(MenuName)
                  item.Name = MenuName
                  WindowsToolStripMenuItem.DropDownItems.Add(item)

                  Scott Dorman

                  Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


                  Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

                  G Offline
                  G Offline
                  Georg Kohler
                  wrote on last edited by
                  #8

                  This got me going ... not everything is working yet , but I was able to search based on a string Your where correct in that I had to set the .name also Thanks a lot

                  S 1 Reply Last reply
                  0
                  • G Georg Kohler

                    This got me going ... not everything is working yet , but I was able to search based on a string Your where correct in that I had to set the .name also Thanks a lot

                    S Offline
                    S Offline
                    Scott Dorman
                    wrote on last edited by
                    #9

                    You're welcome. Glad it going you heading in the right direction.

                    Scott Dorman

                    Microsoft® MVP - Visual C# | MCPD President - Tampa Bay IASA [Blog][Articles][Forum Guidelines]


                    Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups