簡體   English   中英

無法轉換為'System.Collections.IEnumerable

[英]cannot convert to 'System.Collections.IEnumerable

我在類ProductSearch.cs具有以下方法,但在第PagedCollectionView pagingCollection = new PagedCollectionView(e.Result)行上出現錯誤

無法從“ProductSearch.ListOfProducts”到“System.Collections.IEnumerable”轉換

void service_GetObjectCompleted(object sender, GetObjectCompletedEventArgs e)
{
    if (e.Result.Count != 0)
    {
        PagedCollectionView pagingCollection = new PagedCollectionView(e.Result);
        pgrProductGrids.Source = pagingCollection;
        grdProductGrid.ItemsSource = pagingCollection;
    }
}

e包含類的一個對象ListOfProducts其從該本發明的方法獲得在其值service.svn.cs

public ListOfProducts GetObject()
{
    ListOfProducts Listproducts = new ListOfProducts();
    ........
    using (IDataReader reader = cmd.ExecuteReader())
    {
        while (reader.Read())
        {
            Product product = new Product(reader["Name"].ToString(), reader["Code"].ToString());
            Listproducts.Product.Add(product);
        }
    }
    return Listproducts;
}

這里是ListOfProducts

public class ListOfProducts
{
    [DataMember()]
    public List<Product> Product { get; set; }

    public ListOfProducts()
    {
        Product = new List<Product>();
    }
}

請嘗試以下代碼。 應該適合您的情況

    PagedCollectionView pagingCollection = new PagedCollectionView(e.Result.Product);

和整個代碼

void service_GetObjectCompleted(object sender, GetObjectCompletedEventArgs e)
{
    if (e.Result.Count != 0)
    {
        PagedCollectionView pagingCollection = new PagedCollectionView(e.Result.Product);
        pgrProductGrids.Source = pagingCollection;
        grdProductGrid.ItemsSource = pagingCollection;
    }
}

你也可以使用indexer

public Product this[int index]
{
      get { return Product[index]; }
      set { Product[index] = value; }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM