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

How to: Bind a Report to Multiple List Data Sources (Runtime Sample)

  • 3 minutes to read

This tutorial describes the steps used to create a Snap application that is connected to multiple data sources simultaneously. In this tutorial, the application is bound to two independent System.Collections.Generic.List<T> data sources at runtime.

Follow these steps to create a Snap application and connect it to data.

Connect to Data

  1. Start Microsoft Visual Studio 2012, 2013, 2015, 2017 or 2019, and create a new Windows Forms application, or open an existing one.
  2. Drop the SnapControl from the DX19.1: Reporting Toolbox tab on the application’s main form.
  3. To connect the application to data, handle the Load event of the application’s main form and write the following code in the event handler.

    
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.OleDb;
    using System.Windows.Forms;
    using DevExpress.Snap.Core.API;
    // ...
    
    class Cars {
        public int ID { get; set; }
        public string Trademark { get; set; }
        public string Model { get; set; }
    }
    
    class Company {
        public int ID { get; set; }
        public string CompanyName { get; set; }
        public string Address { get; set; }
    }
    
    private void Form1_Load(object sender, EventArgs e) {
    
        List<Cars> e1List = new List<Cars>();
        e1List.Add(new Cars() { ID = 1, Trademark = "Mercedes-Benz", Model = "SL500 Roadster" });
        e1List.Add(new Cars() { ID = 2, Trademark = "BMW", Model = "530i" });
    
        List<Company> e2List = new List<Company>();
        e2List.Add(new Company() { ID = 1, CompanyName = "Doe Enterprises", Address = "123 Home Lane" });
        e2List.Add(new Company() { ID = 2, CompanyName = "Hill Corporation", Address = "45 Hill St." });
    
        snapControl1.Document.BeginUpdateDataSource();
        this.snapControl1.Document.DataSources.Add(new DataSourceInfo("Cars", e1List));
        this.snapControl1.Document.DataSources.Add(new DataSourceInfo("Company", e2List));
        snapControl1.Document.EndUpdateDataSource();
    
    }
    

View the Result

The Snap application is now ready. Run it to create your report.

To design the report layout, drop fields from the Data Explorer onto the report editing surface.

BindReportToMultiple-01