mardi 24 février 2015

How would I dynamically load the subitems of a menustrip at run time?

I thought Id try this place for an answer one more time. I have this code that loads the names of folders in C:\Quiz



For Each dir As String In Directory.GetDirectories("C:\Quiz")
Dim dirinfo As New DirectoryInfo(dir)
MenuStrip1.Items.Add(dirinfo.Name) ' loads the folder names
For Each fn As String In Directory.GetFiles(dir) ' get the txt files in the directory Quiz's subfolders
Next


Im not sure on how to create the toolstripmenuitem object for the menustrip.item and load the quiz questions that are in each folder into their perspective menustrip.item names


the submenus would get loaded at run time. This is what I have tried but to no avail:



'iterate through each file in the current directory (dir)
For Each fn As String In Directory.GetFiles(dir)

'add the file name without the extension to a new ToolStripMenuItem
Dim menuItem As New ToolStripMenuItem(IO.Path.GetFileNameWithoutExtension(fn))

'set the Tag of the new ToolStripMenuItem to the full path and name of the file
menuItem.Tag = fn

'add the new ToolStripMenuItem to your existing (DropDownButton) in the ToolStrip or your (MenuItem) in your MenuStrip
MenuStrip1.Add(menuItem)


This does not populate each menus submenu, the whole idea is to populate the menu and submenu at run time with the folder names in C:\Quiz and the text files which are in each of the folders: C:\Quiz\Genesis\Genesis1.txt, 2.txt.... C:\Quiz\Exodus\Exodus1.txt, 2.txt .... and so on and so forth. I'd appreciate so help on this as Im still learning and have been working on it for a great while. Thank you


Aucun commentaire:

Enregistrer un commentaire