mt70 Posted July 9, 2003 Posted July 9, 2003 I would like to accomplish the following task: 1. Read the names of all folders in c:/temp 2. create a menu item for each folder that is found under c:/temp and name the menu item with the concatanation of "mnu" and "folder name" I can read the names of folders under c:/temp as follows: Dim mystring As String() mystring = System.IO.Directory.GetFileSystemEntries("c:\temp") Now I want to use the following for loop: Dim str As String For Each str In mystring '...question is what do I need to do here -- the following does not work Dim newstring As string newstring = "mnu" & str '...now I have the correct string in newstring which I would like to use as a name for a menu item like so: Dim newstring As New MenuItem() '...the issue is that newstring is already defined as a string and now I am trying to define it as a menu item. '...How do get a menuItem whose name is equal to the value of newstring???? Next str Quote
*Experts* mutant Posted July 9, 2003 *Experts* Posted July 9, 2003 For Each str In MyString Dim mnu As New MenuItem mnu.Name = "mnu" & str Next This should help you :) Quote
mt70 Posted July 9, 2003 Author Posted July 9, 2003 Thanks for the quick response, however I get an error: "Name is not a member of system.Windows.Forms.MenuItem" Please help!! Quote
*Experts* mutant Posted July 9, 2003 *Experts* Posted July 9, 2003 Oh, im sorry I forgot that Menus dont have that property available in code. :rolleyes: Maybe you could identify the menus by their text? Quote
mt70 Posted July 9, 2003 Author Posted July 9, 2003 The issue is that I need to create a "new menu" item each time I loop around in the for loop shown in the code snippet in the original post. Somehow I have to be able to change the name of the menuitem when I am instantiating it in the loop: For each str in mystring Dim <some name based on current value of str> As new menuitem Is this possible or do I need to design the application differently. Basically an example is the that the menu items under "stencils" in VISIO get updated as you add new folders to the "solutions" directory. I am trying to achieve the same thing. Thanks Quote
*Gurus* divil Posted July 9, 2003 *Gurus* Posted July 9, 2003 Menu items don't _have_ names of any kind. They're just objects like everything else. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Mothra Posted July 9, 2003 Posted July 9, 2003 You could try using an XML file to hold the "config" settings, write a routine that runs when the form is instanciated to check the directory for the folders in it and write them to the xml file. Then create the menu items based on the list from the xml file. It does seem like a long way around a short problem however. I think it would work though. Quote Being smarter than you look is always better than looking smarter than you are.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.