Convert BindingList<MyObject> to List<MyObject> c#
Asked Answered
A

3

16

How can I convert BindingList to List ?

Alfreda answered 18/4, 2012 at 7:7 Comment(1)
BindingList implements the IList interface. Are you sure you need an actual List?Immensity
H
23

Try this

List<int> list = yourBindingList.ToList();

int is your type =)

Halliburton answered 18/4, 2012 at 7:11 Comment(2)
I don't see a ToList() or Cast() method with my BindingList nor in MSDN. Is this a different BindingList than System.ComponentModel.BindingList<T>?Knapsack
@RichShealer - A bit late but you need to make sure you add the using System.Linq; ToList() is an extension method.Generate
W
3

If you're using .NET 2.0, then this is the solution:

public List<T> ToList()
{
    return new List<T>(this); // this - is a BindingList compatible object
}
Wellwisher answered 19/11, 2015 at 20:52 Comment(0)
S
2

List list = yourBindingList.Cast().ToList();

Scalenus answered 26/9, 2013 at 8:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.