【问题标题】:System.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSourceSystem.ArgumentException:复杂 DataBinding 接受 IList 或 IListSource 作为数据源
【发布时间】: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来过滤它们。

标签: c# winforms linq


【解决方案1】:

变化:

listBox.DataSource = (dir.ToString()); 

收件人:

listBox.DataSource = dir.ToList();

dir.ToString() 只会吐出一些对可枚举的描述,这没有用。错误消息表明它需要一个列表,因此需要 .ToList()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 2013-10-13
    相关资源
    最近更新 更多