IList or an IListSource error???

P

Paolo

I am trying to populate a Listbox with the results of a query triggered from
a selection in a combo box:

private void cmbxCategory_SelectedValueChanged(object sender, EventArgs e)
{
string theCatId = cmbxCategory.SelectedValue.ToString();
var getSubCat =
from c in dataSet.Category // Category and
Subcategory are typed DataSets
from sc in dataSet.SubCategory
where theCatId == sc.S_CatId
select sc.S_Description;

lsbxSubCat.DataSource = getSubCat; ######
}

I'm getting the following exception at line #####
System.ArgumentException: Complex DataBinding accepts as a data source
either an IList or an IListSource.
at System.Windows.Forms.ListControl.set_DataSource(Object value)
at
ExpenditureLINQDataSets.frmMain.cmbxCategory_SelectedValueChanged(Object
sender, EventArgs e) in L:\Workspace\Visual Studio 2008\Projects\Expenditure
Analysis\ExpenditureLINQDataSets\ExpenditureLINQDataSets\Form1.cs:line #####

I don't know if what I am trying to do is possible so I would appreciate
input on how to achieve my objective.
 
M

Marc Gravell

The LINQ query will be either IEnumerable<T> or IQueryable<T> - but
not IList. The simplest fix is probably to call the .ToList()
extension method:

sbxSubCat.DataSource = getSubCat.ToList();

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top