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: Complex DataBinding accepts as a data source either an IList or an IListSource.
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());
Change:
listBox.DataSource = (dir.ToString());
To:
listBox.DataSource = dir.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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With