menu item to display the contents of a folder  
Author Message
bw12117





PostPosted: Visual Basic Express Edition, menu item to display the contents of a folder Top

How do you program a menu item to display the contents of a folder (Like internet explorer does with favorites)

Visual Studio Express Editions44  
 
 
ahmedilyas





PostPosted: Visual Basic Express Edition, menu item to display the contents of a folder Top

well you would get the list of files from a specified folder:

 

dim theFiles as String() = System.IO.Directory.GetFiles(theFolder)

 

then to display the list of files found in a menu item, you would go through each file in theFiles and add a new menu item

 



Dim theMainMenu as New MainMenu()
for each currentFile as String in theFiles
   theMainMenu.MenuItems.Add(currentFile, new System.EventHandler(AddressOf MenuItem_OnClick)
next
Me.Menu = theMainMenu
 
private sub MenuItem_OnClick(ByVal sender as System.Object, ByVal e as System.EventArgs)
   MessageBox.Show(sender.ToString())
end sub
 

 

 

you may also wish to add an Onclick event handler, this is the second parameter in the Add() method of the MenuItems collection

 

does this help



 
 
bw12117





PostPosted: Visual Basic Express Edition, menu item to display the contents of a folder Top

Yes this helps thanks, I was looking form the item to be displayed in the menu (like favoriteds) rather then a message box.
 
 
ahmedilyas





PostPosted: Visual Basic Express Edition, menu item to display the contents of a folder Top

oh yes that can be changed to your liking, the messagebox was just a thing I added to demonstrate that it works ;-)