C# Winform里面怎么把一个文件夹下面的文件名称读取出来到ComBox的下拉...
发布网友
发布时间:2024-10-24 01:52
我来回答
共2个回答
热心网友
时间:2024-10-27 22:20
string strUserDirPath="你的目录路径";
if (Directory.Exists(strUserDirPath) == true)
{
string[] strArrFiles = Directory.GetFiles(strUserDirPath);
DataTable dt = new DataTable();
DataColumn dc = new DataColumn("user", typeof(string));
dt.Columns.Add(dc);
foreach (string s in strArrFiles)
{
DataRow dr = dt.NewRow();
dr[0] = Path.GetFileName(s);
dt.Rows.Add(dr);
}
return dt;
}
this.cmbox_UserInfo.ValueMember = "user";
this.cmbox_UserInfo.DisplayMember = "user";
this.cmbox_UserInfo.DataSource = dt;
热心网友
时间:2024-10-27 22:22
使用命名空间 System.IO;
//cb_file combox
DirectoryInfo dir = new DirectoryInfo("E:\\资料\\音频视频\\");
foreach (FileInfo d in dir.GetFiles())
{
cb_file.Items.Add(d.Name);
}