【发布时间】:2011-07-11 19:39:00
【问题描述】:
我正在使用下面的 C# 代码来填充 WinForms 列表框。但是,我想隐藏所有系统文件夹。例如 $RecyclingBin。但它给了我以下错误。
System.ArgumentException: Complex DataBinding 接受 IList 或 IListSource 作为数据源。
作为 LINQ 的新手,这让我很困惑。谁能告诉我哪里出错了?
string[] dirs = Directory.GetDirectories(@"c:\");
var dir = from d in dirs
where !d.StartsWith("$")
select d;
listBox.DataSource = (dir.ToString());
【问题讨论】:
-
在这种情况下,我喜欢绑定到DirectoryInfos。比字符串更容易处理,你可以使用Attributes来过滤它们。