如何使用目录中的名称文件填充C#上的组合框 [英] How to fill a combo box on C# with the name files from a directory
本文介绍了如何使用目录中的名称文件填充C#上的组合框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好我有C#项目,当我尝试添加代码时
Hello i have C# project and when i try to add code
private void button5_Click(object sender, EventArgs e)
{
{
string[] files = System.IO.Directory.GetFiles(Path.Combine(@"C:\POS\Book\Book\" + label6.Text, "Prijave"));
{
this.comboBox2.Items.AddRange(files);
}
i我刚刚获得路径。
超出
i am just getting paths.
with out of
Path.Combine
我一无所获
我的尝试:
我试过
i am getting nothing
What I have tried:
I tried
string[] filePaths = Directory.GetFiles(@"C:\POS\Book\Book\" + label6.Text, "Prijave");
foreach (string file in filePaths)
{
combobox2.items.add(file);
}
仍然是同样的问题我没有得到任何我的组合框是空的
still same issue i get nothing my combobox is empty
推荐答案
试试
try
string[] fileNames = System.IO.Directory.GetFiles(Path.Combine(@"D:\DataLoad\" + label6.Text, "Prijave")).Select(k => Path.GetFileName(k)).ToArray();
参考 Path.GetFileName Method(String)(System.IO) [ ^ ]
这篇关于如何使用目录中的名称文件填充C#上的组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文