我正在使用下面的C#代码填充WinForms ListBox.我想隐藏所有系统文件夹.比如$ RecyclingBin.但它给了我以下错误.
System.ArgumentException:复杂DataBinding接受IList或IListSource作为数据源.
作为LINQ的新手,这对我来说不仅仅是让人困惑.谁能告诉我哪里出错了?
string[] dirs = Directory.GetDirectories(@"c:\");
var dir = from d in dirs
where !d.StartsWith("$")
select d;
listBox.DataSource = (dir.ToString());
Run Code Online (Sandbox Code Playgroud)
Kir*_*oll 23
更改:
listBox.DataSource = (dir.ToString());
Run Code Online (Sandbox Code Playgroud)
至:
listBox.DataSource = dir.ToList();
Run Code Online (Sandbox Code Playgroud)
dir.ToString()将简单地吐出一些可枚举的描述,这是无用的.错误消息表明它需要一个列表,因此.ToList().
| 归档时间: |
|
| 查看次数: |
16511 次 |
| 最近记录: |