Skip to main content

Bind a Report to a List Object at Design Time and Supply Data at Runtime

  • 4 minutes to read

This tutorial demonstrates how to use an object data source to bind a report to a List<T> object.

  1. Create a new application or open an existing application. For more information, review the following help topic: Get Started with DevExpress Reporting.

  2. Add a new blank report to it.
  3. Add a new Data.cs file with the following code to the application:

    using System;
    // ...
    namespace WindowsApplication1 {
        public class Data {
            public Data() {
            private int _id;
            private string _name;
            private DateTime _date;
            public int Id {
                get { return this._id; }
                set { this._id = value; }
            public string Name {
                get { return this._name; }
                set { this._name = value; }
            public DateTime Date {
                get { return this._date; }
                set { this._date = value; }
  4. Rebuild the solution.

  5. Invoke the Data Source Wizard and follow the Wizard’s steps to bind the report to the Data object.

  6. Drop data fields from the Field List onto the report.


  7. Handle the Form1_Load event to populate and assign the report’s data source.

    using System;
    using System.Windows.Forms;
    using System.Collections.Generic;
    using DevExpress.XtraReports.UI;
    // ...
    private void Form1_Load(object sender, EventArgs e) {
        XtraReport1 report = new XtraReport1();
        report.DataSource = CreateData();
        ReportPrintTool tool = new ReportPrintTool(report);
    private  List<Data> CreateData() {
        List<Data> data = new List<Data>();
        Data item1 = new Data();
        item1.Date = DateTime.Now;
        item1.Id = 0;
        item1.Name = "First";
        Data item2 = new Data();
        item2.Date = DateTime.Now;
        item2.Id = 1;
        item2.Name = "Second";
        Data item3 = new Data();
        item3.Date = DateTime.Now;
        item3.Id = 2;
        item3.Name = "Third";
        return data;

Run the application and view the result.


Tips and Limitations

A direct assignment of the List<Data> property to the report’s DataSource property at runtime is not recommended because the List<Data> object may be disposed of at some stages of document generation, such as when report parameters are applied.

Use the ObjectDataSource class as the data source and the DataSourceManager class to assign a data source to your report at runtime. Once you bind a report to an object schema, you can access an instance of the ObjectDataSource class and assign the desired data model to that instance. The schema of the assigned model must be equal to the schema of the object to which the report was bound in the Designer.

Note that you can use a model data source object when developing an application, and at runtime replace the model object with a working object.

See Also