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

XtraReportBase.DataSource Property

Gets or sets a data source object that provides data for a master or detail report, as well as to the charts and pivot grids it contains.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v20.2.dll


public object DataSource { get; set; }

Property Value

Type Description

An object representing the report’s data source.


Use the DataSource property to specify a data source for your report. Multiple data source types are supported, including .NET data providers, lists (implementing the IList, ITypedList, or IBindingList interfaces), and XML data sources. To learn more, refer to the Bind Reports to Data topic.

After you’ve set the DataSource property, your data source should be populated with data. This can either be done manually (e.g. by calling the System.Data.Common.DataAdapter.Fill method, if you’re using a DataSet object), or automatically, by assigning the data adapter that was used to create the data source to the XtraReportBase.DataAdapter property.

Finally, specify a data member from where you report should obtain its data, via the XtraReportBase.DataMember property. For more information on binding a report and its controls to data, refer to the Bind Reports to Data and Binding Report Controls to Data sections.

At runtime, you can set the DataSource property (or change its value) in the XtraReportBase.DataSourceDemanded event handler.

Since the DataSource property is declared in the XtraReportBase class, it is also available for the DetailReportBand objects. This allows you to specify different data sources for a master report and its detail report bands. Note that if the DataSource property of a detail report isn’t specified, it uses the data source defined for its parent (the master report). The same applies to the XRChart and XRPivotGrid controls, which have their own XRChart.DataSource and XRPivotGrid.DataSource properties: if these properties aren’t defined, these controls use the data source defined for the report itself. For details on this, refer to Add a Chart (Set Up Series Manually).


When you specify the DataSource property individually for a chart or pivot grid, and the report itself isn’t bound to data, the report’s DataSource property is automatically set to the data source specified for these controls. So, to avoid having your chart or pivot grid repeat as many times as there are records in the data source, set your report’s DataSource property to null (Nothing in Visual Basic).

Note that if a report’s DataSource isn’t available at design time, you still can provide data bindings for report controls at design time within Visual Studio or in the End-User Designer. To do this, if you’re working with a dataset, you can create a data source schema in XML or XSD format, and assign it to the XtraReport.DataSourceSchema property at design time. A similar alternative to other data source types (e.g. List objects), is to use the ObjectDataSource class. For details on this, refer to the Business Object topic.

To learn about the serialization of the DataSource property, refer to Storing Report Layouts.


Since XtraReports uses dots to separate the names of different data items (data source, table, relation, field, etc.), avoid using them in a data source name.


Imports System.Windows.Forms
Imports System
Imports DevExpress.DataAccess.Sql
Imports DevExpress.DataAccess.ConnectionParameters
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports.Configuration

' ...
Private Function BindToData() As SqlDataSource
    ' Create a data source with the required connection parameters.  
    Dim connectionParameters As New Access97ConnectionParameters("../../nwind.mdb", "", "")
    Dim ds As New SqlDataSource(connectionParameters)

    ' Create an SQL query to access the Products table.
    Dim query As New CustomSqlQuery()
    query.Name = "customQuery"
    query.Sql = "SELECT * FROM Products"

    ' Add the query to the collection and return the data source. 

    ' Make the data source structure displayed 
    ' in the Field List of an End-User Report Designer.

    Return ds
End Function

Private Function CreateReport() As XtraReport
    ' Create a new report instance.
    Dim report As New XtraReport()

    ' Assign the data source to the report.
    report.DataSource = BindToData()
    report.DataMember = "customQuery"

    ' Add a detail band to the report.
    Dim detailBand As New DetailBand()
    detailBand.Height = 50

    ' Create a new label.
    Dim label As XRLabel = New XRLabel With {.WidthF = 300}
    ' Specify the label's binding.
    label.ExpressionBindings.Add(New ExpressionBinding("BeforePrint", "Text", "[ProductName]"))
    ' Add the label to the detail band.

    Return report
End Function

Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
    ' Show the report's print preview.
    Dim printTool As New ReportPrintTool(CreateReport())
End Sub

Private Sub button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button2.Click
    ' Open the report in an End-User Report Designer.
    Dim designTool As New ReportDesignTool(CreateReport())
End Sub


See Also