如何将文件列表添加到组合框中?

How to add a list of files into a combo box?

我目前正在使用 VB.Net 开发游戏的帐户系统。我想知道如何使组合框显示特定目录中的文件列表。这就是我的意思:

当用户运行应用程序时,我希望他们看到一个组合框,其中显示了他们计算机上的目录。

我查看了所有教程,但没有发现任何有用的东西。

注意:组合框采用下拉列表样式。

这么多方法——也许是最容易理解的:

For Each f In My.Computer.FileSystem.GetFiles("c:\Logging\")

    MyDropDownList.Items.Add(f)

Next

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));
}

如果您想了解有关类似问题的更多信息,可以访问此 post here