Enables binding data-aware controls and components to a runtime-created object or an instance method.
[ToolboxBitmap(typeof(ResFinder), "Bitmaps256.ObjectDataSource.bmp")] [ToolboxSvgImage("DevExpress.DataAccess.Images.ObjectDataSource.svg,DevExpress.DataAccess.v21.1, Version=126.96.36.199, Culture=neutral, PublicKeyToken=c38a27d2243c2672")] [XRDesigner("DevExpress.DataAccess.UI.Design.XRObjectDataSourceDesigner,DevExpress.DataAccess.v21.1.UI, Version=188.8.131.52, Culture=neutral, PublicKeyToken=c38a27d2243c2672", typeof(IDesigner))] public class ObjectDataSource : DataComponentBase, ITypedList, IList, ICollection, IEnumerable, IListAdapter, IDataComponent, IComponent, IDisposable, ISupportInitialize, IBindingList
<XRDesigner("DevExpress.DataAccess.UI.Design.XRObjectDataSourceDesigner,DevExpress.DataAccess.v21.1.UI, Version=184.108.40.206, Culture=neutral, PublicKeyToken=c38a27d2243c2672", GetType(IDesigner))> <ToolboxBitmap(GetType(ResFinder), "Bitmaps256.ObjectDataSource.bmp")> <ToolboxSvgImage("DevExpress.DataAccess.Images.ObjectDataSource.svg,DevExpress.DataAccess.v21.1, Version=220.127.116.11, Culture=neutral, PublicKeyToken=c38a27d2243c2672")> Public Class ObjectDataSource Inherits DataComponentBase Implements ITypedList, IList, ICollection, IEnumerable, IListAdapter, IDataComponent, IComponent, IDisposable, ISupportInitialize, IBindingList
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.
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.
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.
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).
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.
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.
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).