ObjectDataProvider

This data provider can be used to access object structures. It can work with the following types/interfaces:

  IEnumerable (requires at least one record though)

  IEnumerable<T>

  IListSource

In order to influence the property names and types, you may either implement the ITypedList interface on your class or use the DisplayNameAttribute. To suppress members, use the Browsable(false) attribute on the members.

The provider can also parse empty enumerations as long as they are strongly typed. Otherwise, at least one element is required in the enumeration and this first element determines the type that is used for further parsing.

The provider automatically supports sorting as soon as the data source implements the IBindingList interface.

You may also use this data provider to access LINQ query results, as they are IEnumerable<T>.

When using EntityCollection<T> objects as data source the ObjectDataProvider first checks the state of the sub relation by the IsLoaded property and dynamically calls Load() if necessary. The data is provided when needed with it. Example:

class Car

{

    public string Brand { get; set; }

    public string Model { get; set; }

}

 

List<Car> cars = new List<Car>();

cars.Add(new Car { Brand = "VW", Model = "Passat"});

cars.Add(new Car { Brand = "Porsche", Model = "Cayenne"});

ListLabel LL = new ListLabel();

LL.DataSource = new ObjectDataProvider(cars);

LL.Design();

LL.Dispose();