System.ArgumentException:复杂数据绑定接受IList或IListSource作为数据源 [英] System.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSource

查看:75
本文介绍了System.ArgumentException:复杂数据绑定接受IList或IListSource作为数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的C#代码填充WinForms ListBox.我想隐藏所有系统文件夹.例如,像$ RecyclingBin.但这给了我以下错误.

I'm using the C# code below to populate a WinForms ListBox. I want to hide all System folders however. Like the $RecyclingBin for example. But it gives me the following error.

System.ArgumentException:复杂数据绑定将IList或IListSource接受为数据源.

System.ArgumentException: Complex DataBinding accepts as a data source either an IList or an IListSource.

成为LINQ的新手,这对我来说不仅仅使我感到困惑.谁能告诉我我要去哪里错了?

Being new to LINQ this is more than confusing to me. Can anyone tell me where I'm going wrong?

string[] dirs = Directory.GetDirectories(@"c:\");
var dir = from d in dirs
          where !d.StartsWith("$")
          select d;

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

推荐答案

更改:

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

收件人:

listBox.DataSource = dir.ToList();

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

dir.ToString() will simply spit out some description of the enumerable, which isn't useful. The error message indicates it needs a list, hence the .ToList().

这篇关于System.ArgumentException:复杂数据绑定接受IList或IListSource作为数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆