我在课程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
的Object,它从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>();
}
}
答案 0 :(得分:0)
请尝试以下代码。应该适合您的情况
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; }
}