Convert IList<T> to BindingList<T>

只谈情不闲聊 提交于 2019-11-30 00:54:28

问题


How can I cast an IList<Customer> list to BindingList<Customer>?


回答1:


var yourList = new List<Customer>();
var listBinding = new BindingList<Customer>(yourList);

BindingList Constructors

You don't need to do a cast, just provide the BindingList<T> class constructor with IList<T>, which you have.




回答2:


Unfortunately you can not cast an IList to something its not. However you can create a new BindingList from it fairly easy by just passing your IList into its constructor.

BindingList<Customer> bindingList = new BindingList<Customer>(yourIList);



回答3:


BindingList constructor takes IList parameter, use it:

var binding = new BindingList<Customer>(list); //where list is type of IList<Customer>



回答4:


        IList<Customer> list = new List<Customer>();

        var bindingList = new BindingList<Customer>(list);



回答5:


Additional information: IBindingList inherits from IList: So IBindingList shares all properties and function signatures with IList. So, IList implementations can readily "fit" IBindingList implementations.



来源:https://stackoverflow.com/questions/14953461/convert-ilistt-to-bindinglistt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!