无法将IList转换为绑定列表

时间:2014-08-12 11:10:47

标签: c# winforms bindinglist

我正在开发一个应用程序,我将Object转换为IList。然后我想将其转换为BindingList

以下是我正在尝试的代码

IList data = spareEntity.getall() as IList;
var listBinding = new BindingList<IList>(data);

public object getall()
{
    using (var worldbankAMSentitiesNew = new WorldBankAMSEntities())
    {
        var q = from fullSpareInventory in worldbankAMSentitiesNew.Spare_Inventory
        select new
        {
            fullSpareInventory.Is_Spare,
            fullSpareInventory.Manufacturer,
            fullSpareInventory.Product_No,
            fullSpareInventory.Remarks,
            fullSpareInventory.Remedy_Ticket_No,
            fullSpareInventory.Serial_No,
            fullSpareInventory.Spare_Type,
            fullSpareInventory.Spare_Inventory_Volume.Spare_Name,
            fullSpareInventory.Spare_ID,
            fullSpareInventory.Assigned_Date,
            fullSpareInventory.Description,
            fullSpareInventory.Spare_Volume_ID
        };
        return q.ToList();
    }
}

2 个答案:

答案 0 :(得分:2)

你可以尝试如下: -

var yourList = spareEntity.getall() as List<Object>;
var listBinding = new BindingList<Object>(yourList);

答案 1 :(得分:1)

new BindingList<IList>(data);

我认为这里的IList类型是错误。使用IList数据使用的泛型类型。备用?什么......

尝试对象

new BindingList<object>(data);

更改你的getall()

public IList<object> getall()

var data = spareEntity.getall();