Back to Devexpress

DataSourceManager.GetDataSourceAssignables<TDataSourceAssignable>(XtraReport, Boolean) Method

xtrareports-devexpress-dot-xtrareports-dot-datasourcemanager-dot-getdatasourceassignables-1-x28-devexpress-dot-xtrareports-dot-ui-dot-xtrareport-system-dot-boolean-x29.md

latest3.5 KB
Original Source

DataSourceManager.GetDataSourceAssignables<TDataSourceAssignable>(XtraReport, Boolean) Method

Returns a report and its elements (subreports, controls, bands, parameters) that match the specified type and to which a data source can be assigned.

Namespace : DevExpress.XtraReports

Assembly : DevExpress.XtraReports.v25.2.dll

NuGet Package : DevExpress.Reporting.Core

Declaration

csharp
public static IEnumerable<TDataSourceAssignable> GetDataSourceAssignables<TDataSourceAssignable>(
    XtraReport report,
    bool includeSubReports = false
)
    where TDataSourceAssignable : class, IDataSourceAssignable
vb
Public Shared Function GetDataSourceAssignables(Of TDataSourceAssignable As {Class, IDataSourceAssignable})(
    report As XtraReport,
    includeSubReports As Boolean = False
) As IEnumerable(Of TDataSourceAssignable)

Parameters

NameTypeDescription
reportXtraReport

A report instance

|

Optional Parameters

NameTypeDefaultDescription
includeSubReportsBooleanFalse

true to include elements from the subreports; otherwise, false.

|

Type Parameters

NameDescription
TDataSourceAssignable

The type of report elements.

|

Returns

TypeDescription
IEnumerable<TDataSourceAssignable>

A collection that includes the report and its elements.

|

Example

The following code sample shows how to retrieve a report and all its subreports (elements of the XtraReport type) and update settings (the ConnectionName property) of their data sources. In this example, we assume that the type of each data source is SqlDataSource.

csharp
using DevExpress.DataAccess.Sql;
using DevExpress.XtraReports.UI;
using DevExpress.XtraReports;
//...

var report = new XtraReport1();

var dataBoundReports = DataSourceManager.GetDataSourceAssignables<XtraReport>(
    report: report,
    includeSubReports: true
);

foreach (var dataBoundReport in dataBoundReports) {
    (dataBoundReport.DataSource as SqlDataSource).ConnectionName = "nwind";
}
vb
Imports DevExpress.DataAccess.Sql
Imports DevExpress.XtraReports.UI
Imports DevExpress.XtraReports
'...

Private report = New XtraReport1()

Private dataBoundReports = DataSourceManager.GetDataSourceAssignables(Of XtraReport)(report:= report, includeSubReports:= True)

For Each dataBoundReport In dataBoundReports
    TryCast(dataBoundReport.DataSource, SqlDataSource).ConnectionName = "nwind"
Next dataBoundReport

See Also

DataSourceManager Class

DataSourceManager Members

DevExpress.XtraReports Namespace