Convert IList<T> to BindingList<T>

依然范特西╮ 提交于 2019-11-30 17:16:31
LukeHennerley
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.

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);

BindingList constructor takes IList parameter, use it:

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

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

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

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