XtraReportBase.DataSourceDemanded Event

Occurs before report generation, to specify a data source for the report.

Namespace: DevExpress.XtraReports.UI

Assembly: DevExpress.XtraReports.v20.2.dll


public event EventHandler<EventArgs> DataSourceDemanded
Public Event DataSourceDemanded As EventHandler(Of EventArgs)

Event Data

The DataSourceDemanded event's data class is EventArgs.


In a handler of this event, you can set or modify a value of the report's XtraReportBase.DataSource property.

You can handle the DataSourceDemanded event to silently pass parameters to a report and populate the report's data source using a stored procedure.

When this event is raised, all report parameters have already been initialized or assigned values in a Print Preview. You can handle this event to obtain their values.


This example illustrates a workaround enabling you to use multi-value parameters in a query string.

At present, query parameters cannot be directly mapped to multi-value report parameters, and this task is solved by adding a WHERE clause to the SQL string in the following way.

SELECT [Categories].[CategoryID], [Categories].[CategoryName] FROM [Categories] [Categories]
 WHERE [Categories].[CategoryID] IN (1,2,3)

To dynamically update the query string using the values assigned to a report parameter (whose Parameter.MultiValue property is set to true), use the following code in the XtraReportBase.DataSourceDemanded event handler.

Imports DevExpress.DataAccess.Sql
Imports System
Imports System.Collections
Imports System.Text
' ...

Namespace WindowsFormsApplication3
    Partial Public Class XtraReport1
        Inherits DevExpress.XtraReports.UI.XtraReport

        Public Sub New()

            ' Assign a set of values to the report parameter.
            Me.parameter1.Value = New Integer() { 1, 2, 3 }

            ' Handle the DataSourceDemanded event of a report.
            AddHandler Me.DataSourceDemanded, AddressOf XtraReport1_DataSourceDemanded
        End Sub

        Private Sub XtraReport1_DataSourceDemanded(ByVal sender As Object, ByVal e As EventArgs)
            Dim query As CustomSqlQuery = TryCast(Me.sqlDataSource1.Queries(0), CustomSqlQuery)
            Dim count As Integer = (TryCast(Me.parameter1.Value, IList)).Count
            If count = 0 Then
            End If
            Dim builder As New StringBuilder()
            For i As Integer = 0 To count - 1
                'builder.Append('\''); // Uncomment this line when parsing a string parameter value.
                builder.Append((TryCast(Me.parameter1.Value, IList))(i))
                'builder.Append('\''); // Uncomment this line when parsing a string parameter value.
                If i <> count - 1 Then
                End If
            Next i

            query.Sql &= " WHERE [Categories].[CategoryID] IN " & builder.ToString()
        End Sub
    End Class
End Namespace
See Also