Sunday, July 12, 2009

How to call a list from a button on a GUI?

Basically I want to make a very simple GUI, I have folders named a,b,c,d etc...





And I want to make a Button for each letter, and when pressed I would like it to bring up the contents of that folder maybe in a box of some sort on the GUI but I am not 100% sure how this works.





And the last part would be after the GUI shows the contents of that folder I would want a certain program to open the file when selected.





I know how to design the GUI but I don't know the code to do the above mentioned or what type of box or whatever I need to display the folder.





Using Microsoft Visual studio, with Visual Basic as a Language.





If you cant help can you link me to a really good programming forum where I could pose this question.





TIA





-Daniel

How to call a list from a button on a GUI?
It has been a long time since I've programmed in Visual Basic, but I found some sample code on the web. As for the display, I'd probably put it in a ListView, which is the same view you see in Windows Explorer.





Here's the code snippets:





Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


' make a reference to a directory


Dim di As New IO.DirectoryInfo("c:\")


Dim diar1 As IO.FileInfo() = di.GetFiles()


Dim dra As IO.FileInfo





'list the names of all files in the specified directory


For Each dra In diar1


ListBox1.Items.Add(dra)


Next


End Sub


No comments:

Post a Comment