MenuStrip control searching by menue name
-
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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
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 stringMenuName
. 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 theName
property. To do this it would be something like this:ToolStripItem item = WindowsToolStripMenuItem.DropDownItems.Add(MenuName)
item.Name = MenuName2. 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
-
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 stringMenuName
. 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 theName
property. To do this it would be something like this:ToolStripItem item = WindowsToolStripMenuItem.DropDownItems.Add(MenuName)
item.Name = MenuName2. 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
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
-
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
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