Skip to main content
All docs
V21.2

DataSourceManager Class

Allows you to get data source(s) from a report or controls.

Namespace: DevExpress.XtraReports

Assembly: DevExpress.XtraReports.v21.2.dll

Declaration

public static class DataSourceManager

Remarks

Use the static methods declared in this class to get data sources from a report and its controls/parameters, replace a data source, or add data sources to a report.

Operation Methods
Get data sources The GetDataSources overloaded methods
Get controls and parameters that have data sources The GetDataSourceAssignables overloaded methods
Get controls and parameters that have the specified data source The GetDataSourceAssignablesByDataSource(XtraReport, Object, Boolean) method
Add data sources to a report The AddDataSources(XtraReport, IComponent[]) method

The DataSourceManager class helps you accomplish the following tasks:

  • Retrieve all data sources referenced in a report.
  • Change the report data source without affecting the detail report.
  • Replace the report data source at runtime.
  • Replace mock data with live data when users switch to Preview.

Example

The following code retrieves all data sources in a report and its controls, and populates these data sources with data:

using DevExpress.XtraReports.UI;
using DevExpress.DataAccess.Json;
using DevExpress.XtraReports;
// ...

// Create a report and assign a JSON data source to it.
XtraReport report = new XtraReport();
var jsonDataSource1 = new JsonDataSource();
report.DataSource = jsonDataSource1;

// Add the report's BeforePrint event handler.
report.BeforePrint += PopulateDataSources;

// Create a chart and place it in the report's footer band.
DetailBand detailBand = new DetailBand();
ReportFooterBand reportFooterBand = new ReportFooterBand();
report.Bands.AddRange(new Band[] { detailBand, reportFooterBand });
XRChart chart = new XRChart();
var jsonDataSource2 = new JsonDataSource();
chart.DataSource = jsonDataSource2;
reportFooterBand.Controls.Add( chart );

// ...
// Retrieve all data sources from the report and its controls.
private void PopulateDataSources(object sender, System.Drawing.Printing.PrintEventArgs e) {
  var report = sender as XtraReport;
  var dataSources = DataSourceManager.GetDataSources(report, true);
  foreach (var dataSource in dataSources) {
    (dataSource as JsonDataSource).Fill();
  }
}

Inheritance

Object
DataSourceManager
See Also