Skip to main content
A newer version of this page is available. .

ObjectDataSource Class

Enables binding data-aware controls and components to a runtime-created object or an instance method.

Namespace: DevExpress.DataAccess.ObjectBinding

Assembly: DevExpress.DataAccess.v19.2.dll

Declaration

[XRDesigner("DevExpress.DataAccess.UI.Design.XRObjectDataSourceDesigner,DevExpress.DataAccess.v19.2.UI, Version=19.2.99.0, Culture=neutral, PublicKeyToken=c38a27d2243c2672", typeof(IDesigner))]
[ToolboxBitmap(typeof(ResFinder), "Bitmaps256.ObjectDataSource.bmp")]
[ToolboxSvgImage("DevExpress.DataAccess.Images.ObjectDataSource.svg,DevExpress.DataAccess.v19.2, Version=19.2.99.0, Culture=neutral, PublicKeyToken=c38a27d2243c2672")]
public class ObjectDataSource :
    DataComponentBase,
    ITypedList,
    IList,
    ICollection,
    IEnumerable,
    IListAdapter,
    IDataComponent,
    IComponent,
    IDisposable,
    ISupportInitialize

Remarks

ObjectDataSource can be used to supply the following controls/components with data.

Use the ObjectDataSource when your data is provided by an object or there is a method that returns the data as an object, and it is not required to connect to a database to obtain the data.

When such an object cannot be accessed from your application code, you can use the ObjectDataSource to obtain the data. For example, it is possible to launch the Data Source wizard at runtime and use it to select a required assembly (from among those referenced in the project), and within it, a specific type and method without rebuilding your project and writing any code.

An ObjectDataSource can be bound to a public class or public member (property or method) of a public class that returns an object implementing the IEnumerable<T> interface. This member can either be a static, or instance property (method).

The following properties are used to bind the ObjectDataSource to data.

  • ObjectDataSource.DataSource

    It can be assigned a specific object instance or a type.

    Because the Data Source wizard cannot be used for binding to a specific object instance, it is required to assign this instance to the DataSource property in code before calling the ObjectDataSource.Fill method. In the wizard, this scenario corresponds to the “Retrieve the data source schema” option.

    If the DataSource property has been assigned a type, the ObjectDataSource will try to create an instance of this type when calling the ObjectDataSource.Fill method (this will require specifying the constructor parameters, which is explained further in this article). In the wizard, this scenario corresponds to the “Retrieve the actual data” option.

    Note

    If the ObjectDataSource.DataMember property (see below) has been assigned a static member, creating an instance of the corresponding type is not required, nor is specifying the constructor parameters.

  • ObjectDataSource.DataMember

    To bind the ObjectDataSource to an object, leave this property set to null. In the wizard, this scenario corresponds to the following option: “Do not select a member, bind to the entire object”.

    To bind the ObjectDataSource to a property or method, assign its name to the DataMember property. When binding to a method, it is also required to specify this method’s parameters (as described further in this article).

  • ObjectDataSource.Parameters

    To bind to a method, this collection must contain parameters that are required to call this method and obtain the data. In any other case, leave this collection empty.

  • ObjectDataSource.RebuildResultSchema
    Call this method to build the data source schema.
    Call the RebuildResultSchema(IEnumerable<IParameter>) overloaded method instead to apply values from external parameters (for instance, report parameters) to the data source parameters before the schema is built.

  • ObjectDataSource.Constructor

    If it is required that on calling the ObjectDataSource.Fill method, an ObjectDataSource should create an instance of the type specified by its ObjectDataSource.DataSource property, use the Constructor property to specify the required constructor parameters. To assign a constructor without parameters, use the static ObjectConstructorInfo.Default object.

    For a code sample, see the following example online: How to programmatically generate ObjectDataSource and map object data source constructor parameters to report parameters.

    Set this property to null for the ObjectDataSource to never try to create an object instance (if you need to manually create and assign it, or when binding to a static member).

To make a specific assembly, class or member appear in the Data Source wizard, use the following attributes: HighlightedAssemblyAttribute, HighlightedClassAttribute and HighlightedMemberAttribute.

Implements

Inheritance

Object
MarshalByRefObject
Component
DevExpress.DataAccess.DataComponentBase

Extension Methods

Show 24 items
See Also