Binding to Object Data Sources
- 2 minutes to read
The Dashboard Designer allows you to connect to an object data source defined in a separate class within the current project.
Creating a Data Source in the Data Source Wizard
To bind a dashboard to an object data source, do the following.
Click the New Data Source button in the Data Source ribbon tab.
On the first page of the invoked Data Source Wizard dialog, select Object Binding and click Next.
On the next page, select the assembly containing the definition of the required class.
Click Next.
Select the class providing the required data and click Next.
For instance, this can be a custom class providing the required data or any TableAdapter used to query a database.
On the final page, select the required data member used to obtain data and click Finish.
This creates the data source and displays its fields in the Data Source Browser.
Note
The collection returned by a data class must implement the IEnumerable or IListSource interface.
Creating a Data Source in Code
To create an object data source in code, create an instance of the DashboardObjectDataSource class and specify the following properties:
- Specify the type of the required class using the ObjectDataSource.DataSource property.
- Specify the data member using the ObjectDataSource.DataMember property.
- If necessary, specify constructor parameters using the ObjectDataSource.Constructor property.
- Use the ObjectDataSource.Fill method to retrieve data from the object data source.
Finally, add the created DashboardObjectDataSource object to the Dashboard.DataSources collection.
The following code snippet shows how to create an object data source and add it to the collection of dashboard data sources:
using DevExpress.DashboardCommon;
// ...
Dashboard dashboard = new Dashboard();
DashboardObjectDataSource objectDataSource = new DashboardObjectDataSource();
objectDataSource.DataSource = typeof(Student);
objectDataSource.DataMember = "GetData";
objectDataSource.Constructor = ObjectConstructorInfo.Default;
objectDataSource.Fill();
dashboard.DataSources.Add(objectDataSource);