Quote Originally Posted by arcon5
I wish to construct a menu within my mnuOne menu item at runtime.

I want to do it based on the structure of the folders,

files within folders are structured as follows:

Line1: Name
Line1: Location

Which would be opened using FileOpen.

How would I construct the menu at runtime in VB which creates a menu item for each file and folder in location "c:/myfolder"

E.g.
Directory c:/myfolder structure is as follows:
c:/myfolder/fil1.txt
c:/myfolder/file2.txt
c:/myfolder/directory/file1.txt
c:/myfolder/dir2/fil1.txt

I would want a menu as follows:
mnuOne/filename
mnuOne/file2name
mnuOne/directory/file1name
mnuOne/dir2/file1name

Thanks
well to get all the folders and names i suggest using the function i made.
(supply it with 2 arrays to put the paths in.)(example)

VB Code:
  1. Public Class Form1
  2.     Dim file() As String
  3.     Dim folder() As String
  4.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  5.         ReDim file(9999999)
  6.         ReDim folder(9999999)
  7.         getfiles("C:\myfolder\", file, folder)
  8.         ReDim Preserve file(filesamount - 1)
  9.         ReDim Preserve folder(foldersamount - 1)
  10.     End Sub
  11.  
  12.     Dim foldersamount As Integer
  13.     Dim filesamount As Integer
  14.     Private Sub getfiles(ByVal path As String, ByVal allfiles() As String, ByVal allfolders() As String)
  15.         Dim directoryi As New IO.DirectoryInfo(path)
  16.         Dim directorys() As IO.DirectoryInfo = directoryi.GetDirectories
  17.         Dim files() As IO.FileInfo = directoryi.GetFiles
  18.         Dim directory As IO.DirectoryInfo
  19.         Dim file As IO.FileInfo
  20.         For Each file In files
  21.             allfiles(filesamount) = file.FullName
  22.             filesamount += 1
  23.         Next
  24.         For Each directory In directorys
  25.             allfolders(foldersamount) = directory.FullName
  26.             foldersamount += 1
  27.             getfiles(directory.FullName, allfiles, allfolders)
  28.         Next
  29.     End Sub
  30. End Class


heres an example of creating a menustrip then adding to it.


VB Code:
  1. Public Class Form1
  2.  
  3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.         Dim menu As New MenuStrip 'declare it
  5.         Controls.Add(menu) 'add it to the project
  6.         menu.Show() 'display the menu strip
  7.         menu.Items.Add("Test") 'add the first item
  8.     End Sub
  9. End Class

not sure on how to add a handler or a child but that should get u started.