Skip to main content

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.v24.2.dll

Declaration

[ToolboxBitmap(typeof(ObjectDataSource), "ObjectDataSource.bmp")]
public class ObjectDataSource :
    DataComponentBase,
    ITypedList,
    IList,
    ICollection,
    IEnumerable,
    IListAdapter,
    IDataComponent,
    IComponent,
    IDisposable,
    ISupportInitialize,
    IBindingList,
    IDynamicLookupSettingsDataProvider

Remarks

Overview

The ObjectDataSource is a data component much like the standard .NET BindingSource component.

The ObjectDataSource component has the following advantages over BindingSource:

  • It can bind to methods that return a collection of custom objects.
  • It can bind to parameterized object constructors.
  • Since it is a cross-platform component, your project does not need the System.Windows.Forms assembly.

Note

The Object Data Source displays only public non-static properties in the Field List.

Refer to the following help topic for examples of use: Use ObjectDataSource.

Data Source for Controls and Components

The following help topics decribe how to use the ObjectDataSource to supply DevExpress controls/components with data:

You can use the Data Source Wizard to bind a component to an Object Data Source. To make a particular assembly, class, or member appear in the Data Source Wizard, use the following attributes: HighlightedAssemblyAttribute, HighlightedClassAttribute, and HighlightedMemberAttribute.

ObjectDataSource Properties

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.

    View Example: How to Create a Report Bound to the ObjectDataSource with Constructor Parameters Linked 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).

Implements

See Also