Reputation: 143
I'm currently working on an account system for a game using VB.Net. I was wondering how to make it so that a combo box displays a list of files within a specific directory. Here's what I mean:
When the user runs the application, I want them to see a combo box displaying a directory on their computer.
I've looked at all of the tutorials, but found NOTHING that worked.
NOTE: The combobox is in a dropdownlist style.
Upvotes: 1
Views: 7062
Reputation: 3531
VB.NET
Dim dir = "Your Path"
For Each file As String In System.IO.Directory.GetFiles(dir)
ComboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file))
Next
C#
dynamic dir = "Your Path";
foreach (string file in System.IO.Directory.GetFiles(dir))
{
this.comboBox1.Items.Add(System.IO.Path.GetFileNameWithoutExtension(file));
}
You can visit this post if you want more information about a similar question here
Upvotes: 1
Reputation: 4742
So many ways--perhaps the easiest to understand:
For Each f In My.Computer.FileSystem.GetFiles("c:\Logging\")
MyDropDownList.Items.Add(f)
Next
Upvotes: 1